def graphviz_plot(graph, fname="tmp_dotgraph.dot", show=True):
if os.path.exists(fname):
print("WARNING: Overwriting existing file {} for new plots".format(fname))
f = open(fname,'w')
f.writelines('digraph G {\nnode [width=.3,height=.3,shape=octagon,style=filled,color=skyblue];\noverlap="false";\nrankdir="LR";\n')
for i in graph:
for j in graph[i]:
s= ' '+ i
s += ' -> ' + j + ' [label="' + str(graph[i][j]) + '"]'
s+=';\n'
f.writelines(s)
f.writelines('}')
f.close()
graphname = fname.split(".")[0] + ".png"
pe(["dot", "-Tpng", fname, "-o", graphname])
if show:
plt.imshow(mpimg.imread(graphname))
plt.show()
评论列表
文章目录