在OSMnx的图中添加一个点

8
我正在尝试在 Jupyter 笔记本中向现有的 OSMnx 绘图添加一个点,方法如下:
import osmnx as ox
import matplotlib.pyplot as plt

G = ox.graph_from_address('1600 Pennsylvania Ave NW, Washington, DC 20500', 
                          distance=500)

fig, ax = ox.plot_graph(G)

ax.scatter(-77.036498, 38.897270, c='red')

plt.show()

但是我的点(-77.036498, 38.897270)没有显示出来。有什么想法吗?

print (type(fig), type(ax))
<class 'matplotlib.figure.Figure'> <class 'matplotlib.axes._subplots.AxesSubplot'>

enter image description here

1个回答

14

问题是ox.plot_graph会在你绘制点之前显示你的图形。请注意,如果您设置show=Falseox.plot_graph将默认关闭该图形。您需要将ox.plot_graph更改为:

fig, ax = ox.plot_graph(G, show=False, close=False)
希望以下的图表是您想要的:

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接