You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The package name on pip is python-louvain
but it is imported as community in python.
More documentation for this module can be found at
https://python-louvain.readthedocs.io/
Usage
To use as a Python library
fromcommunityimportcommunity_louvainimportmatplotlib.cmascmimportmatplotlib.pyplotaspltimportnetworkxasnx# load the karate club graphG=nx.karate_club_graph()
# compute the best partitionpartition=community_louvain.best_partition(G)
# draw the graphpos=nx.spring_layout(G)
# color the nodes according to their partitioncmap=cm.get_cmap('viridis', max(partition.values()) +1)
nx.draw_networkx_nodes(G, pos, partition.keys(), node_size=40,
cmap=cmap, node_color=list(partition.values()))
nx.draw_networkx_edges(G, pos, alpha=0.5)
plt.show()
It can also be run on the command line
$ community <filename>
where filename is a binary file as generated by the
convert utility distributed with the C implementation at
https://sites.google.com/site/findcommunities/
However as this is mostly for debugging purposes its use should be avoided.
Instead importing this library for use in Python is recommended.