NetworkX

Previous topic

connected_components

Next topic

node_connected_component

connected_component_subgraphs

connected_component_subgraphs(G)[source]

Return connected components as subgraphs.

Parameters :

G : NetworkX Graph

An undirected graph.

Returns :

glist : list

A list of graphs, one for each connected component of G.

Notes

The list is ordered from largest connected component to smallest. For undirected graphs only.

Graph, node, and edge attributes are copied to the subgraphs.

Examples

Get largest connected component as subgraph

>>> G=nx.path_graph(4)
>>> G.add_edge(5,6)
>>> H=nx.connected_component_subgraphs(G)[0]