2

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

sten
  • 7,028
  • 9
  • 41
  • 63
  • 1
    Please provide a sample input and output. It's not clear to me what you are asking to do. (I think you are using the word 'generate' differently from what I would mean). – Joel Feb 19 '17 at 05:04
  • You can change the order of either axis easily: see [Reverse Y-Axis in PyPlot](http://stackoverflow.com/a/8280500) (@Joel's answer keeps the positioning under your control, which may be advantageous in other ways) – Bonlenfum Feb 21 '17 at 12:00

1 Answers1

3

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)
Joel
  • 22,598
  • 6
  • 69
  • 93