我正在尝试在 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'>
最佳答案
问题是ox.plot_graph
将在您绘制您的观点之前显示您的图表。请注意,如果您设置 show=False
, ox.plot_graph
将默认关闭图窗。您将需要更改您的 ox.plot_graph
到:
fig, ax = ox.plot_graph(G, show=False, close=False)
希望下图是您想要的:
关于python - 向 OSMnx 图中添加一个点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49460880/