I'm trying to add a point to an existing OSMnx plot in a Jupyter notebook like so
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()
but my point(-77.036498, 38.897270) is not showing up. Any ideas?
print (type(fig), type(ax))
<class 'matplotlib.figure.Figure'> <class 'matplotlib.axes._subplots.AxesSubplot'>
The problem is ox.plot_graph
will show your graph before you plot your point. And please note that if you set show=False
, ox.plot_graph
will close the figure by default. You will need to change your ox.plot_graph
to:
fig, ax = ox.plot_graph(G, show=False, close=False)
Hopefully the following graph is what you want:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With