Skip to content

Instantly share code, notes, and snippets.

@manekgarg
Created May 23, 2020 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manekgarg/e4d373febbab1717a17b0646d84ed48d to your computer and use it in GitHub Desktop.
Save manekgarg/e4d373febbab1717a17b0646d84ed48d to your computer and use it in GitHub Desktop.
# Import the packages
import community
from importlib import reload
# reload(community)
# or use Girvan-Newman algorithm
# Assgin the community function to c_values
communities = community.best_partition(G.to_undirected(), resolution = .75)
c_values = [communities.get(node) for node in G.nodes()]
# Plot the the graph again with community using c_values as color
plt.figure(figsize=(22,16))
nx.draw(G, edge_color = '#ced7d9',width = 4, arrowsize = 30, node_color = c_values, with_labels= True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment