Converting Dot To Png In Python
Answer :
Load the file with pydot.graph_from_dot_file
to get a pydot.Dot
class instance. Then write it to a PNG file with the write_png
method.
import pydot
(graph,) = pydot.graph_from_dot_file('somefile.dot')
graph.write_png('somefile.png')
pydot needs the GraphViz binaries to be installed anyway, so if you've already generated your dot file you might as well just invoke dot directly yourself. For example:
from subprocess import check_call
check_call(['dot','-Tpng','InputFile.dot','-o','OutputFile.png'])
You can use pygraphviz. Once you have a graph loaded, you can do
graph.draw('file.png')
Comments
Post a Comment