sten
sten

Reputation: 7476

NetworkX : Flip graph

Is there a way to make graph generation in the opposite order i.e. I want to generate the graph vertically flipped.

or if I can flip it with some matplotlib subroutine before it is drawn !!

F.e.: I want 357 and 358 to be on top, and 1-6 to be at the bottom

enter image description here

Upvotes: 2

Views: 2268

Answers (1)

Joel
Joel

Reputation: 23837

Just interchange the coordinates of your positions.

import networkx as nx
import matplotlib.pyplot as plt

G = fast_gnp_random_graph(20,0.1)
pos = nx.sprint_layout(G)
nx.draw_networkx(G, pos=pos)
flipped_pos = {node: (x,-y) for (node, (x,y)) in pos.items())
plt.clf()
nx.draw_networkx(G, pos = flipped_pos)

Upvotes: 3

Related Questions