andrey.viz.layout#
- andrey.viz.layout(structure, engine='auto', options=None)[source]#
Return the node positions
draw()uses when none are given.Pass the result as
positions=to draw several structures over the same nodes, such as an estimate and its truth, with every node in the same place.- Parameters:
structure (
GraphStructure) – Any kind.engine (
str) –"dot"lays the nodes out in ranks along the directed edges, causes on the left;"neato","fdp","sfdp","circo","twopi","osage", and"patchwork"are Graphviz’s other layouts. These need pygraphviz, thevizextra."builtin"needs nothing: nodes in layers along the directed edges, or on a circle when there are none or they form a cycle."auto"is"dot"when pygraphviz is installed, and"builtin"otherwise.options (
Mapping[str,object] |None) – Graphviz graph attributes, such as{"rankdir": "TB"}to run causes top to bottom, or{"nodesep": 1}to spread nodes within a rank. The built-in layout takes none.
- Returns:
Each node’s
(x, y)in the unit square,ydownward, in the layout’s proportions: the longer side spans the square, and the shorter one is centered.- Return type:
- Raises:
TypeError – If
structureis not aGraphStructure, such as aTemporalStructure.ValueError – If
engineis not one of the above, or the built-in layout is givenoptions.ImportError – If a Graphviz engine is named and pygraphviz is not installed.
Examples
>>> import numpy as np >>> from andrey.core.structure import GraphStructure, TAIL, ARROW >>> import andrey.viz >>> M = np.zeros((2, 2), np.int8); M[0, 1] = TAIL; M[1, 0] = ARROW # X -> Y >>> andrey.viz.layout(GraphStructure.from_numpy(M, kind="dag"), engine="builtin") {0: (0.0, 0.5), 1: (1.0, 0.5)}