ccc_graph.py 文件源码

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

项目:ccc_helper 作者: TimothyZhang 项目源码 文件源码
def create_image(g, path):
    path = os.path.relpath(path)

    if pygraphviz:
        a = nx.nx_agraph.to_agraph(g)
        # ['neato'|'dot'|'twopi'|'circo'|'fdp'|'nop']
        a.layout(prog='neato', args="-Goverlap=false -Gsplines=true")  # splines=true
        a.draw(path)
    elif plt:
        nodes = g.nodes(True)
        colors = [attrs['color'] for n, attrs in nodes]
        labels = {n: attrs['label'] for n, attrs in nodes}

        if graphviz_layout:
            pos = graphviz_layout(g)
        else:
            pos = nx.spring_layout(g)
        nx.draw_networkx_nodes(g, pos, node_shape='o', node_color=colors, alpha=0.3)
        nx.draw_networkx_edges(g, pos, style='solid', alpha=0.2)
        nx.draw_networkx_labels(g, pos, labels, alpha=0.5)
        # plt.show()
        plt.imsave(path)  # todo: this is not tested!

    print 'Image saved to', path
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号