33import numpy as np
44import networkx as nx
55import networkx .algorithms .community as nx_community
6- from community import best_partition , generate_dendrogram
6+ from community import community_louvain
77
88
99class MidpointNormalize (colors .Normalize ):
@@ -81,7 +81,7 @@ def add_louvain_communities(graph, all_levels=False, random_state=None):
8181 if all_levels :
8282 # We add the first communities detected, The dendrogram at level 0 contains the nodes as keys
8383 # and the clusters they belong to as values.
84- dendrogram = generate_dendrogram (graph_communities , random_state = random_state )
84+ dendrogram = community_louvain . generate_dendrogram (graph_communities , random_state = random_state )
8585 partition = dendrogram [0 ]
8686 cnodes = set (partition .values ())
8787 graph .add_nodes_from (cnodes , NodeType = 'subcommunity' )
@@ -108,7 +108,7 @@ def add_louvain_communities(graph, all_levels=False, random_state=None):
108108 nx .set_node_attributes (graph , cluster_child_parent2 , 'parent' )
109109 # Update nodes clusters
110110 else :
111- communities = best_partition (graph_communities , random_state = random_state )
111+ communities = community_louvain . best_partition (graph_communities , random_state = random_state )
112112 # compound nodes to add to hold communities
113113 cnodes = set (communities .values ())
114114 graph .add_nodes_from (cnodes , NodeType = 'community' )
0 commit comments