Skip to content

Commit

Permalink
⬆️ viz
Browse files Browse the repository at this point in the history
  • Loading branch information
GiulioRossetti committed May 13, 2024
1 parent 6ee359f commit 43eedd0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cdlib/viz/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@
(0.5, 0.5, 0.5),
)


def __filter(partition: list, top_k: int, min_size: int) -> list:
if isinstance(min_size, int) and min_size > 0:
partition = list(filter(lambda nodes: len(nodes) >= min_size, partition))
if isinstance(top_k, int) and top_k > 0:
partition = partition[:top_k]
return partition


def plot_network_clusters(
graph: object,
partition: NodeClustering,
Expand Down Expand Up @@ -253,7 +255,7 @@ def plot_network_highlighted_clusters(
:param cmap: str or Matplotlib colormap, Colormap(Matplotlib colormap) for mapping intensities of nodes. If set to None, original colormap is used.
:param top_k: int, Show the top K influential communities. If set to zero or negative value indicates all.
:param min_size: int, Exclude communities below the specified minimum size.
:param edge_weights: The weight of the edges within clusters. Useful for spring_layout.
:param edge_weights_intracluster: The weight of the edges within clusters. Useful for spring_layout.
Example:
Expand All @@ -266,8 +268,7 @@ def plot_network_highlighted_clusters(
"""
if not isinstance(cmap, (type(None), str, matplotlib.colors.Colormap)):
raise TypeError(
"The 'cmap' argument must be NoneType, str or matplotlib.colors.Colormap, "
"not %s." % (type(cmap).__name__)
f"The 'cmap' argument must be NoneType, str or matplotlib.colors.Colormap, not{type(cmap).__name__}."
)

partition = __filter(partition.communities, top_k, min_size)
Expand Down

0 comments on commit 43eedd0

Please sign in to comment.