pydsa.graphs¶
draw_graph ¶
draw_graph(
G: Dict[Any, Union[Dict[Any, Any], Any]],
) -> None
Utility function to draw a graph (stored as dict of dicts, dict of lists, or dict with (row, col) tuples as keys) in the terminal as a colored adjacency matrix. Requires 'tabulate' library: pip install tabulate For colors, requires 'colorama': pip install colorama Colors edges based on values (e.g., 1 in red, 0 in blue). Assumes nodes are comparable for sorting.
Source code in pydsa/graphs.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
as_dict_of_dicts ¶
as_dict_of_dicts(G: Any) -> Any
Accept a dict of lists (or tuples or sets) as well as a dict of dicts. Each list neighbor becomes a dict entry with weight 1.
Also accept a dict of scalars (each key has one neighbor, its value) and a list of ints (a parent array: index i has one neighbor parent[i]). A self loop, parent[i] == i, draws as a node with no outgoing edge.
Source code in pydsa/graphs.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
draw_ascii_graph ¶
draw_ascii_graph(
graph: Dict[Any, Union[Dict[Any, Any], List[Any]]],
) -> None
Utility function to draw a graph (stored as dict of dicts or dict of lists) in the terminal using PHART for ASCII rendering. Requires 'networkx' and 'phart' libraries: pip install networkx phart Supports directed graphs. Edge weights (like 0/1) are ignored in rendering but structure is shown.
Source code in pydsa/graphs.py
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 | |