Still kinda new to NetworkX here, but I wanted to be able to query a NetworkX graph to find all nodes within a cluster of nodes. Here is an example graph I had generated:
As you can see, there are clusters of nodes. Within each cluster, every node is connected to every other node. You can see that in a zoom-up of five such clusters below:
I'd like to be able to find out how I can extract out each individual cluster of nodes. Each node is named with a long name ("A/Vietnam/2009/8/431", for example), and I know how to fish out an individual node using NetworkX's functions, but I don't know how to get all connected nodes within that cluster. Language of preference is Python (2.7), and I have been using the NetworkX package in conjunction.
Thanks everybody!
import networkx as nx
#G is the networkx graph
sub_graphs = nx.connected_component_subgraphs(G)
#n gives the number of sub graphs
n = len(sub_graphs)
# you can now loop through all nodes in each sub graph
for i in range(n):
print "Subgraph:", i, "consists of ",sub_graphs[i].nodes()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With