You are here

Python-Networkx: community detection and plotting

Tidied up from here:


import matplotlib
import matplotlib.pyplot as plt #optional - to output image at end
import networkx as nx
import community #part of python-louvain by Thomas Aynaud

G = nx.random_graphs.powerlaw_cluster_graph(300, 1, .4)
part = community.best_partition(G)
values = [part.get(node) for node in G.nodes()]
nx.draw_spring(G, cmap = plt.get_cmap('jet'), node_color = values, node_size=30, with_labels=False)
plt.savefig('community_test.png') #optional output image

Links: (parts missing/incomplete)