可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have a dot file generated from my code and want to render it in my output. For this i have seen on the net that the command is something like this on cmd
dot -Tpng InputFile.dot -o OutputFile.png for Graphviz
But my problem is that I want to use this inbuilt in my python program.
How can i do so ??
I looked at pydot but can't seem to find an answer in there.....
回答1:
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'])
回答2:
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')
回答3:
You can use pygraphviz. Once you have a graph loaded, you can do
graph.draw('file.png')