- edge_subgraph(G, edges)¶
Returns a view of the subgraph induced by the specified edges.
The induced subgraph contains each edge in
edgesand each node incident to any of those edges.
- GNetworkX Graph
An iterable of edges. Edges not present in
- subgraphSubGraph View
A read-only edge-induced subgraph of
G. Changes to
Gare reflected in the view.
To create a mutable subgraph with its own copies of nodes edges and attributes use
If you create a subgraph of a subgraph recursively you can end up with a chain of subgraphs that becomes very slow with about 15 nested subgraph views. Luckily the edge_subgraph filter nests nicely so you can use the original graph as G in this function to avoid chains. We do not rule out chains programmatically so that odd cases like an
restricted_viewcan be created.
>>> 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)]