user1772523
user1772523

Reputation: 141

Why does NetworkX automatically rotate graph when executed

I'm exercising the NetworkX examples found at networkx.lanl.gov/examples

Each time I run the weighted_graph example, the graph appears to have rotated. Why does the graph rotate?

Is there a way to control the rotation so that the graph is always in the same position?

Upvotes: 3

Views: 1687

Answers (1)

Aric
Aric

Reputation: 25289

What you are seeing is the result of the nx.spring_layout() algorithm that is being used to position the nodes. The algorithm starts with a random position of the nodes so the result is nondeterministic.

You can, however, specify an initial position that is not random e.g. use a circular layout like this,

pos=nx.circular_layout(G)
pos=nx.spring_layout(G,dim=2,pos=pos) # positions for all nodes

and then you should get the same result every time.

Upvotes: 2

Related Questions