def show_graph_communities(graph, partition, color_map=None, with_labels=False):
if color_map is None:
color_map = generate_color_map(partition)
pos = nx.spring_layout(graph,k=0.1,iterations=50)
comm_nodes = utils.partition_to_comm_nodes_map(partition)
for comm, nodes in comm_nodes.items():
nx.draw_networkx_nodes(graph, pos, nodelist=nodes, node_size=400,
node_color=color_map.get(comm), label=comm, cmap=plt.cm.jet)
if with_labels:
nx.draw_networkx_labels(graph, pos, font_size=12)
nx.draw_networkx_edges(graph, pos, alpha=0.3)
plt.legend()
plt.axis('off')
plt.show()
评论列表
文章目录