cottax.consumers.visualization.visualization module¶
A graph as nodes and links: DOT source (to_dot, render) or a matplotlib axis (draw). A box is a model, an ellipse a source, a hexagon a problem; dashed is no body, or no driver.
- networkx_graph(graph: NestingGraph, *, boundary: bool = False)[source]¶
The graph as a drawing sees it: a vertex per node (node, its definition) and, with boundary, one per boundary variable (kind ‘free’ or ‘sink’); each edge carries the variables along it (vars). Refuses a boundary variable spelt as a node is.
- Return type:
DiGraph
- layered_pos(g: DiGraph, *, horizontal: bool = True, sweeps: int = 4)[source]¶
Positions in layers, sources first, laid out on the condensation so a cycle’s members share a layer. A node with no predecessors sits one layer before its first reader; each layer is ordered by barycentre over sweeps passes. horizontal: layers run left to right. For a large graph, to_dot lays out better.
- Return type:
dict
- draw(graph: NestingGraph | ExecutableGraph | Plan | DiGraph, ax=None, *, boundary: bool = True, collapse_boundary: bool = False, input_label: str | None = None, output_label: str | None = None, pos: dict | None = None, layout: str = 'auto', names: bool = True, node_size: int = 2400, font_size: int = 8, style: Style | str = TERRACOTTA, formatter: Formatter = PlainFormat())[source]¶
Draw a NestingGraph, a Plan, a proof (each as graph_drawn reads it) or an already-built nx.DiGraph onto a matplotlib axis (a new one if ax is None); returns the axis.
boundary, collapse_boundary, input_label, output_label, style, formatter: as to_dot. A vertex that is not a place (a caller’s nx.DiGraph) is written as str. pos: positions given; else layout, ‘dot’ (needs graphviz), ‘layered’ (layered_pos) or ‘auto’ (dot when installed). names: the variable names on the edges. node_size, font_size: matplotlib’s.
- to_dot(graph: NestingGraph | ExecutableGraph | Plan | DiGraph, *, boundary: bool = True, collapse_boundary: bool = False, input_label: str | None = None, output_label: str | None = None, rankdir: str = 'LR', style: Style | str = TERRACOTTA, blocks: bool = False, formatter: Formatter = PlainFormat(), font: str | None = None, font_size: int = 10, edge_font_size: int = 9, nodesep: float = 0.35, ranksep: float = 0.6, node_margin: str = '0.14,0.08', margin: float | None = None)[source]¶
graph as Graphviz DOT source (producing it needs nothing installed). graph is read as draw reads it.
boundary: a vertex per boundary variable. collapse_boundary: those merged into two boxes, one every free input comes from and one every result goes into, labelled input_label / output_label through formatter.label (None: ‘In’ / ‘Out’). rankdir: graphviz’s. style: a Style or a name in STYLES. blocks: every solve a cluster, nested as the solves nest, in its band and ring colours. formatter: how a name is written; a marked-up label becomes an HTML-like one. font: the face (the style’s, else Helvetica); font_size, edge_font_size: a vertex’s and an edge’s type. nodesep, ranksep: the spacing; node_margin: a vertex’s (“x,y”, inches); margin: the drawing’s (none by default).
- Return type:
str
- render(graph: NestingGraph | ExecutableGraph | Plan | DiGraph, **kw)[source]¶
to_dot(graph, **kw) as a graphviz.Source, which Jupyter displays inline as SVG.