Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import community # this is pip install python-louvain
- import networkx as nx
- import matplotlib.pyplot as plt
- # Replace this with your networkx graph loading depending on your format !
- # using graph g as a completed graph, weights between 0 and 1
- #first compute the best partition
- partition = community.best_partition(g)
- #drawing
- size = float(len(set(partition.values())))
- pos = nx.spring_layout(g)
- count = 0.
- 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.1)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement