Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. import community # this is pip install python-louvain
  2. import networkx as nx
  3. import matplotlib.pyplot as plt
  4.  
  5. # Replace this with your networkx graph loading depending on your format !
  6.  
  7. # using graph g as a completed graph, weights between 0 and 1
  8.  
  9. #first compute the best partition
  10. partition = community.best_partition(g)
  11.  
  12. #drawing
  13. size = float(len(set(partition.values())))
  14. pos = nx.spring_layout(g)
  15. count = 0.
  16. for com in set(partition.values()) :
  17. count = count + 1.
  18. list_nodes = [nodes for nodes in partition.keys() if partition[nodes] == com]
  19. nx.draw_networkx_nodes(g, pos, list_nodes, node_size = 20, node_color = str(count / size))
  20.  
  21.  
  22. nx.draw_networkx_edges(g, pos, alpha=0.1)
  23.  
  24. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement