Closed clayms closed 3 years ago
Ok, figured it out
from graphviz import Digraph, Source
g1_body = Source.from_file(filename="g1.gv").source.split('\n')[1:-2]
g1_digraph = Digraph(body=g1_body)
g2.subgraph(g1_digraph)
g2
Thanks for documenting.
Source
only loads (does not parse) the file, but as the body
of (Di)Graph
is a list
of lines you can get away with operations on the list strings in simple cases.
See https://graphviz.readthedocs.io/en/stable/#see-also for libraries that parse DOT.
We could make Source
iterable so one could do list(<Source instance>)[1:-2]
.
Is there a way to convert the
graphviz.files.Source
type tographviz.dot.Digraph
type?I would like to import a
.gv
file and use it as a subgraph in another graph.However, the following fails.
However, even though the imported
Source
file (g1_file
) can be rendered the same as the in-memoryDigraph
(g1
), it cannot be added as a subgraph as it is aSource
object, not aDigraph
object.