dynetworkx.ImpulseGraph.to_subgraph

ImpulseGraph.to_subgraph(begin, end, inclusive=(True, True), multigraph=False, edge_data=False, edge_timestamp_data=False, node_data=False)

Return a networkx Graph or MultiGraph which includes all the nodes and edges which have timestamps within the given interval.

Parameters:
  • begin (int or float) –
  • end (int or float) – Must be bigger than or equal to begin.
  • inclusive (2-tuple boolean that determines inclusivity of begin and end) –
  • multigraph (bool, optional (default= False)) – If True, a networkx MultiGraph will be returned. If False, networkx Graph.
  • edge_data (bool, optional (default= False)) – If True, edges will keep their attributes.
  • edge_timestamp_data (bool, optional (default= False)) – If True, each edge’s attribute will also include its timestamp data. If edge_data= True and there already exist edge attributes named timestamp it will be overwritten.
  • node_data (bool, optional (default= False)) – if True, each node’s attributes will be included.

See also

to_snapshots()
divide the impulse graph to snapshots

Notes

If multigraph= False, and edge_data=True or edge_interval_data=True, in case there are multiple edges, only one will show with one of the edge’s attributes.

Note: nodes with no edges will not appear in any subgraph.

Examples

>>> G = dnx.ImpulseGraph()
>>> G.add_edges_from([(1, 2, 10), (2, 4, 11), (6, 4, 19), (2, 4, 15)])
>>> H = G.to_subgraph(4, 12)
>>> type(H)
<class 'networkx.classes.graph.Graph'>
>>> list(H.edges(data=True))
[(1, 2, {}), (2, 4, {})]
>>> H = G.to_subgraph(10, 12, edge_timestamp_data=True)
>>> type(H)
<class 'networkx.classes.graph.Graph'>
>>> list(H.edges(data=True))
[(1, 2, {'timestamp': 10}), (2, 4, {'timestamp': 11})]
>>> M = G.to_subgraph(4, 12, multigraph=True, edge_timestamp_data=True)
>>> type(M)
<class 'networkx.classes.multigraph.MultiGraph'>
>>> list(M.edges(data=True))
[(1, 2, {'timestamp': 10}), (2, 4, {'timestamp': 11})]