networkx 2.8.2 Pypi GitHub Homepage
Other Docs
NotesParametersReturnsBackRef
induced_subgraph(G, nbunch)

The induced subgraph of a graph on a set of nodes N is the graph with nodes N and edges from G which have both ends in N.

Notes

To create a mutable subgraph with its own copies of nodes edges and attributes use :None:None:`subgraph.copy()` or :None:None:`Graph(subgraph)`

For an inplace reduction of a graph to a subgraph you can remove nodes: :None:None:`G.remove_nodes_from(n in G if n not in set(nbunch))`

If you are going to compute subgraphs of your subgraphs you could end up with a chain of views that can be very slow once the chain has about 15 views in it. If they are all induced subgraphs, you can short-cut the chain by making them all subgraphs of the original graph. The graph class method :None:None:`G.subgraph` does this when G is a subgraph. In contrast, this function allows you to choose to build chains or not, as you wish. The returned subgraph is a view on G.

Parameters

G : NetworkX Graph
nbunch : node, container of nodes or None (for all nodes)

Returns

subgraph : SubGraph View

A read-only view of the subgraph in G induced by the nodes. Changes to the graph G will be reflected in the view.

Returns a SubGraph view of G showing only nodes in nbunch.

Examples

>>> G = nx.path_graph(4)  # or DiGraph, MultiGraph, MultiDiGraph, etc
... H = nx.induced_subgraph(G, [0, 1, 3])
... list(H.edges) [(0, 1)]
>>> list(H.nodes)
[0, 1, 3]
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.classes.function.induced_subgraph

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/classes/function.py#352
type: <class 'function'>
Commit: