Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a point to an OSMnx plot

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'>

enter image description here

like image 360
Bob Haffner Avatar asked Mar 24 '18 03:03

Bob Haffner


1 Answers

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:

enter image description here

like image 92
Y. Luo Avatar answered Oct 13 '22 13:10

Y. Luo