Invert one edge in a network graphics

I found DiGraph.reverse()

to change the direction of all edges in a directed graph, but is there a way to change the direction of only a specific edge?

+3


source to share


1 answer


It can be done manually, but there is nothing in the API.



$ cat edges.py; echo; python edges.py 
import networkx as nx
G=nx.DiGraph()
G.add_edge(1,2,{'weight':.5})
G.add_edge(3,4,{'weight':1.0})
attrs = G[1][2]
G.remove_edge(1,2)
G.add_edge(2,1,attrs)
print G.edges(data=True)

[(2, 1, {'weight': 0.5}), (3, 4, {'weight': 1.0})]
$ 

      

+2


source







All Articles