NetworkX:翻转图 [英] NetworkX : Flip graph

查看:68
本文介绍了NetworkX:翻转图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以按相反的顺序生成图,即我想垂直翻转生成图.

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

或者如果我可以在绘制它之前使用一些matplotlib子例程翻转它!!

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

F.e .:我希望357和358位于顶部,而1-6位于底部

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

推荐答案

只需交换位置的坐标即可.

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)

这篇关于NetworkX:翻转图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆