To preprocess the DOT source of a .Graph
or .Digraph
with the unflatten preprocessor (manpage, PDF), use the ~.Graph.unflatten
method.
>>> import graphviz # doctest: +NO_EXE
>>> w = graphviz.Digraph('wide')
>>> w.edges(('0', str(i)) for i in range(1, 10))
>>> doctest_mark_exe() # skip this line
>>> w.view() # doctest: +SKIP
Hint
~.Graph.unflatten
improves the aspect ratio of graphs with many leaves or disconnected nodes.
>>> u = w.unflatten(stagger=3) # doctest: +NO_EXE
>>> doctest_mark_exe() # skip this line
>>> u.view() # doctest: +SKIP
The method returns a .Source
object that you can ~.Source.render
, ~.Source.view
, etc. with the same basic API as .Graph
or .Digraph
objects (minus modification, see details below <using-raw-dot>
).
>>> u = w.unflatten(stagger=2) # doctest: +NO_EXE >>> u # doctest: +ELLIPSIS <graphviz.sources.Source object at 0x...>
>>> doctest_mark_exe() # skip this line
>>> u.view() # doctest: +SKIP