Graph.edge_subgraph#

Graph.edge_subgraph(edges)[source]#

Returns the subgraph induced by the specified edges.

The induced subgraph contains each edge in edges and each node incident to any one of those edges.

Parameters:
edgesiterable

An iterable of edges in this graph.

Returns:
GGraph

An edge-induced subgraph of this graph with the same edge attributes.

Notes

The graph, edge, and node attributes in the returned subgraph view are references to the corresponding attributes in the original graph. The view is read-only.

To create a full graph version of the subgraph with its own copy of the edge or node attributes, use:

G.edge_subgraph(edges).copy()

Examples

>>> G = nx.path_graph(5)
>>> H = G.edge_subgraph([(0, 1), (3, 4)])
>>> list(H.nodes)
[0, 1, 3, 4]
>>> list(H.edges)
[(0, 1), (3, 4)]