简体   繁体   English

NetworkX:翻转图

[英]NetworkX : Flip graph

Is there a way to make graph generation in the opposite order ie I want to generate the graph vertically flipped. 有没有一种方法可以以相反的顺序生成图,即我想垂直翻转生成图。

or if I can flip it with some matplotlib subroutine before it is drawn !! 或者如果我可以在绘制之前使用一些matplotlib子例程翻转它!

Fe: I want 357 and 358 to be on top, and 1-6 to be at the bottom Fe:我希望357和358位于顶部,而1-6位于底部

在此处输入图片说明

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM