graph_tools.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:tools 作者: kastnerkyle 项目源码 文件源码
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()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号