向 OSMnx 图添加一个点
Adding a point to an OSMnx plot
我正在尝试向 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)
希望下图是你想要的:
我正在尝试向 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)
希望下图是你想要的: