helpers.py 文件源码

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

项目:Simulator 作者: libsmelt 项目源码 文件源码
def output_clustered_graph(graph, name, clustering):
    """Will ommit edge labels
    """

    # Create AGraph via networkx
    G = nx.DiGraph()
    G.add_nodes_from(graph.nodes())
    G.add_edges_from(graph.edges())

    A = to_agraph(G)

    tableau20 = [ '#1f77b4', '#aec7e8', '#ff7f0e', '#ffbb78',
                  '#2ca02c', '#98df8a', '#d62728', '#ff9896',
                  '#9467bd', '#c5b0d5', '#8c564b', '#c49c94',
                  '#e377c2', '#f7b6d2', '#7f7f7f', '#c7c7c7',
                  '#bcbd22', '#dbdb8d', '#17becf', '#9edae5' ]
    clist = [ tableau20[i*2] for i in range(0, len(tableau20)/2)]

    i = 0
    for c in clustering:
        A.add_subgraph(c, name='cluster_%d' % i, color=clist[i % len(clist)])
        i += 1

    name = 'graphs/%s.png' % name
    A.write(name + '.dot')
    A.draw(name, prog="dot")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号