You are here

Python-Networkx: community detection and plotting

Tidied up from here: http://ryancompton.net/2014/06/16/community-detection-and-colored-plotti...

Output:

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 https://pypi.python.org/pypi/python-louvain

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:

https://bitbucket.org/taynaud/python-louvain

http://perso.crans.org/aynaud/communities/index.html

https://blog.dominodatalab.com/social-network-analysis-with-networkx/

http://www.sociology-hacks.org/?p=67 (parts missing/incomplete)

https://sites.google.com/site/findcommunities/

Tags: