2

My code is of the form as shown below. How can i output the communities object in a graph ? I tried using plot(communities) but i got does not support plotting.

import igraph as ig

from edgeboost.EdgeBoost import CommunityEdgeBoost

G = ig.Graph.Erdos_Renyi(200,0.1)

#creates EdgeBoost object 
... edgeBooster = CommunityEdgeBoost(lambda 
x:x.community_multilevel(),"common_neighbors",numIterations = 10)

#detect communities
... communities = edgeBooster.detect_communities(G)

print communities
[[0, 34, 55, 57, 94, 136, 191, 105, 116, 124, 170], [1, 24, 36, 98, 
100, 142, 150, 173, 38, 43, 44, 51, 66, 69, 84, 97, 141, 155, 185], 
[2, 74, 83, 6, 31, 48, 109, 113, 121, 127, 160, 163, 174, 175], 
.....]
Girish
  • 23
  • 4

1 Answers1

0

It's very easy. Use this:

import igraph as ig
from edgeboost.EdgeBoost import CommunityEdgeBoost

G = ig.Graph.Erdos_Renyi(200,0.1)

#creates EdgeBoost object 
edgeBooster = CommunityEdgeBoost(lambda x:x.community_multilevel(),"common_neighbors",numIterations = 10)

#detect communities
communities = edgeBooster.detect_communities(G)

Now here is the trick:

# Define the community/subgraph/subnetwork
community_0 = G.subgraph(communities[0])

#plot it
ig.plot(community_0)

Repeat for the communities that you want.

See also: https://stackoverflow.com/a/44881027/5025009

seralouk
  • 30,938
  • 9
  • 118
  • 133