cdlib.viz.plot_community_graph

cdlib.viz.plot_community_graph(graph: object, partition: NodeClustering, figsize: tuple = (8, 8), node_size: int | dict = 200, plot_overlaps: bool = False, plot_labels: bool = False, cmap: object | None = None, top_k: int | None = None, min_size: int | None = None, show_edge_weights: bool = True, show_edge_widths: bool = True, show_node_sizes: bool = True) object

This function plots a graph where each node represents a community, and nodes are color-coded based on their community assignments generated by a community detection algorithm. In this representation, each node in the graph represents a detected community, and edges between nodes indicate connections between communities.

Parameters:
  • graph – NetworkX/igraph graph

  • partition – NodeClustering object

  • figsize – the figure size; it is a pair of float, default (8, 8)

  • node_size – The size of nodes. It can be an integer or a dictionary mapping nodes to sizes. Default is 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.

  • show_edge_widths – Flag to control if edge widths are shown. Default is True.

  • show_edge_weights – Flag to control if edge weights are shown. Default is True.

  • show_node_sizes – Flag to control if node sizes are shown. Default is True.

Example:

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