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")
评论列表
文章目录