2

I want to plot a scatter plot over a shapefile plot, but when I plot the scatter, the first layer disappears.

The code I use is the following:

fig, ax=plt.subplots(figsize=(30,30))
barcelona.plot(ax=ax,column='n_distri',legend=True)
plt.scatter(df.longitud, df.latitud)
plt.show()

enter image description here enter image description here

1 Answer 1

1

For continuous plotting on the same converse, you need to match the ax.
It creates a new plot without options for ax.

plt.scatter(df.longitud, df.latitud)

Use this instead of the one above.

ax.scatter(df.longitud, df.latitud)

If you need to adjust the coordinate system, etc., change the points long and lat to GeoDataFrame and plot, use the ax option.

barcelona.plot(ax=ax,column='n_distri',legend=True)
gdf_of_points.plot(ax=ax)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.