dynetworkx.SnapshotGraph.subgraph

SnapshotGraph.subgraph(nbunch, sbunch=None)

Return a snapshot graph containing only the nodes in bunch, and snapshot indexes in sbunch.

Parameters:
  • nbunch (container of nodes) – Each node in the nbunch list will be included in all subgraphs indexed in sbunch.
  • sbunch (container of edges, optional (default= None)) – Each snapshot index in this list will be included in the returned list of subgraphs. It is highly recommended that this list is sequential, however it can be out of order.
Returns:

snap_graph – Contains only the nodes in bunch, and snapshot indexes in sbunch.

Return type:

SnapshotGraph object

Examples

>>> G = dnx.SnapshotGraph()
>>> G.add_snapshot([(1, 2), (2, 3), (4, 6), (2, 4)])
>>> G.add_snapshot([(1, 2), (2, 3), (4, 6), (2, 4)])
>>> H = G.subgraph([4, 6])
>>> type(H)
<class 'snapshotgraph.SnapshotGraph'>
>>> list(H.get([0])[0].edges(data=True))
[(4, 6, {})]