You could start by loading the file using https://code.google.com/p/pydot/ . From there it should be relatively simply to write the code to traverse the in-memory graph according to an input string.
Pydot is a Python library, also written in Python, that "serves as a graphical interface to Graphviz, an open source graph visualization software. GraphViz is written in DOT language, but Pydot provides the ability to parse and dump data, between Python and DOT."[
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')
You can try:
import os
os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz2.38/bin/'
os.system('dot -Tpng random.dot -o random.png')
You can use graphviz:
# Convert a .dot file to .png
from graphviz import render
render('dot', 'png', 'fname.dot')
# To render an existing file in a notebook
from graphviz import Source
Source.from_file("fname.dot")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With