cdlib.viz.plot_network_highlighted_clusters¶
- cdlib.viz.plot_network_highlighted_clusters(graph: object, partition: NodeClustering, position: dict | None = None, figsize: tuple = (8, 8), node_size: int = 200, plot_overlaps: bool = False, plot_labels: bool = False, cmap: object | None = None, top_k: int | None = None, min_size: int | None = None, edge_weights_intracluster: int = 200) object¶
This function plots a network with highlighted communities, node color coding for communities and draws polygons around clusters. It utilizes spring_layout from NetworkX to position nodes, bringing intra-cluster nodes closer. When considering edge weights, this layout adjusts node positions accordingly, facilitating clearer visualizations of community structures.
- Parameters:
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, the size of nodes. 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.
edge_weights_intracluster – The weight of the edges within clusters. Useful for spring_layout.
Example:
>>> from cdlib import algorithms, viz >>> import networkx as nx >>> g = nx.karate_club_graph() >>> coms = algorithms.louvain(g) >>> position = nx.spring_layout(g) >>> viz.plot_network_highlighted_clusters(g, coms, position)