In [1]:
%pylab inline
import networkx as nx
import pygraphviz as pgz
import StringIO
import tempfile
from IPython.display import Image
In [2]:
dotStr = """digraph {
node [ fill=cornflowerblue,
fontcolor=white,
shape=diamond,
style=filled];
Step1 [ color=darkgoldenrod2,
fontcolor=navy,
label=start,
shape=box];
Step2;
Step3a [ style=filled,
fillcolor=grey80,
color=grey80,
shape=circle,
fontcolor=navy];
Step1 -> Step2;
Step1 -> Step2a;
Step2a -> Step3a;
Step3;
Step3a -> Step3;
Step3a -> Step2b;
Step2 -> Step2b;
Step2b -> Step3;
End [ shape=rectangle,
color=darkgoldenrod2,
fontcolor=navy];
Step3 -> End [label=193];
}"""
#handle = StringIO.StringIO(dotStr)
with open('example.dot','w') as handle:
handle.write(dotStr)
In [3]:
nxG = nx.Graph(nx.read_dot('example.dot'))
nx.draw_networkx(nxG)
In [4]:
gzG = pgz.AGraph(thing = dotStr)
prog = ['neato','dot','twopi','circo','fdp','nop']
gzG.draw('pgz_example.png',prog = prog[1])
Image('pgz_example.png')
Out[4]:
In [ ]: