plot_network_clusters(graph, partition, position=None, figsize=(8, 8), node_size=200, plot_overlaps=False, plot_labels=False, cmap=None, top_k=None, min_size=None)

Plot a graph with node color coding for communities.

  • graph – NetworkX/igraph graph
  • partition – NodeClustering object
  • position – A dictionary with nodes as keys and positions as values. Example: networkx.fruchterman_reingold_layout(G). By default, uses nx.spring_layout(g)
  • figsize – the figure size; it is a pair of float, default (8, 8)
  • node_size – int, default 200
  • plot_overlaps – bool, default False. Flag to control if multiple algorithms memberships are plotted.
  • plot_labels – bool, default False. Flag to control if node labels are plotted.
  • cmap – str or Matplotlib colormap, Colormap(Matplotlib colormap) for mapping intensities of nodes. If set to None, original colormap is used.
  • top_k – int, Show the top K influential communities. If set to zero or negative value indicates all.
  • min_size – int, Exclude communities below the specified minimum size.


>>> from cdlib import algorithms, viz
>>> import networkx as nx
>>> g = nx.karate_club_graph()
>>> coms = algorithms.louvain(g)
>>> pos = nx.spring_layout(g)
>>> viz.plot_network_clusters(g, coms, pos)