I\'ve just started doing graphs in networkx and I want to follow the evolution of a graph in time: how it changed, what nodes/edges are in the graph at a specified time t.
You may select nodes by conditions with list comprehension with G.nodes()
method:
selected_nodes = [n for n,v in G.nodes(data=True) if v['since'] == 'December 2008']
print (selected_nodes)
Out: [1, 2]
To select edges use G.edges_iter
or G.edges
methods:
selected_edges = [(u,v) for u,v,e in G.edges(data=True) if e['since'] == 'December 2008']
print (selected_edges)
Out: [(1, 2)]
To plot selected nodes call G.subgraph()
H = G.subgraph(selected_nodes)
nx.draw(H,with_labels=True,node_size=3000)
To plot selected edges with attributes you may construct new graph:
H = nx.Graph(((u, v, e) for u,v,e in G.edges_iter(data=True) if e['since'] == 'December 2008'))
nx.draw(H,with_labels=True,node_size=3000)
plt.show()