I have detected connected components in my graph. Now I would need to plot them in separate charts for analyzing them individually.As example I am using karate club network, but my network has actually 5 connected components.
JavaScript
x
5
1
G = nx.karate_club_graph()
2
3
connected_com=[len(c) for c in sorted(nx.connected_components(G), key=len, reverse=True)]
4
S = [G.subgraph(c).copy() for c in nx.connected_components(G)]
5
I used nx.draw but nothing has been displayed:
JavaScript
1
4
1
plt.figure()
2
nx.draw(S)
3
plt.show()
4
Advertisement
Answer
S
is not a subgraph but a list of subgraphs so you have to iterate over list even there is only one subgraph (this is the case for karate_club_graph dataset):
JavaScript
1
7
1
plt.figure()
2
for s in S:
3
nx.draw(s)
4
plt.show()
5
6
# For this dataset, nx.draw(G) give the same result
7