def draw_partition(graph, partition):
# requires matplotlib.pyplot, uncomment above
# uses community code and sample from http://perso.crans.org/aynaud/communities/ to draw matplotlib graph in shades of gray
g = graph
count = 0
size = float(len(set(partition.values())))
pos = nx.spring_layout(g)
for com in set(partition.values()):
count = count + 1
list_nodes = [nodes for nodes in partition.keys()
if partition[nodes] == com]
nx.draw_networkx_nodes(g, pos, list_nodes, node_size=20,
node_color=str(count / size))
nx.draw_networkx_edges(g, pos, alpha=0.5)
plt.show()
评论列表
文章目录