0

I have following networkx graph excerpt:

enter image description here

Following functions were executed to explore the structure of connected components, as I have a sparse network with lots of singular connections:

nx.number_connected_components(G) 
>>> 702

list(nx.connected_components(G))
>>> [{120930, 172034},
 {118787, 173867, 176202},
 {50376, 151561}, 
...]

Question: How can I restrict my whole graph visualization to connected_components with equal or more than three nodes?

Christopher
  • 2,120
  • 7
  • 31
  • 58

2 Answers2

2

We can create a subgraph containing the components with equal or more than three nodes:

s = G.subgraph(
    set.union(
        *filter(lambda x: len(x) >= 3, nx.connected_components(G))
    )
)

Now you just need to visualize this subgraph s.

We might need to make a copy instead of a SubGraph view, in that case, s = s.copy() will make a copy from the subgraph.

ducminh
  • 1,312
  • 1
  • 8
  • 17
2
graphs = list(nx.connected_component_subgraphs(G))
list_subgraphs=[items for i in graphs for items in i if len(i)>=3]
F=G.subgraph(list_subgraphs)

Creating a flat list of the subgraphs with components greater than 3 nodes lets say!

PriyankaP
  • 109
  • 6