I am working with a regular network of 100x100=10000
nodes. The network is created just like this:
import networkx as nx
import matplotlib.pyplot as plt
N=100
G=nx.grid_2d_graph(N,N) #2D regular graph of 10000 nodes
pos = dict( (n, n) for n in G.nodes() ) #Dict of positions
labels = dict( ((i, j), i + (N-1-j) * N ) for i, j in G.nodes() )
nx.relabel_nodes(G,labels,False)
pos = {y:x for x,y in labels.iteritems()} #An attempt to change node indexing
I want to have node 0
in the upper left corner, and node 9999
in the lower right. This is why you see a second call to pos
: it is an attempt to change node indexing according to my will.
However, I have noticed that after I run the script:
pos[0]=(0,99)
, pos[99]=(99,99)
, pos[9900]=(0,0)
, pos[9999]=(99,0)
.
This means that networkx
sees the origin of the grid in the bottom left corner and that the farthest position from the origin, (99,99)
, belongs to the 99th node.
Now, I want to change that so to have my origin in the upper left corner. This means that I want to have:
pos[0]=(0,0)
, pos[99]=(0,99)
, pos[9900]=(99,0)
, pos[9999]=(99,99)
.
What should I change in pos
?