使用 NetworkX/Matplotlib 在正确位置绘制坐标节点

6 python graph matplotlib networkx

我知道 x/y 轴被翻转了(柏林位于汉堡的东南部),但是我需要手动修复这个问题还是 matplotlib/networkx 可以为我做这个?如果这需要手动完成,有没有最好的方法呢?

import networkx as nx

G = nx.Graph()

G.add_node('Hamburg', pos=(53.5672, 10.0285))
G.add_node('Berlin', pos=(52.51704, 13.38792))

nx.draw(G, nx.get_node_attributes(G, 'pos'), with_labels=True, node_size=0)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

hel*_*err 3

您可以使用

from matplotlib import pyplot

pyplot.gca().invert_yaxis()
pyplot.gca().invert_xaxis()
Run Code Online (Sandbox Code Playgroud)