Reputation: 1492
Thanks to the answer to this question I can plot the geopandas world map with continents and oceans coloured in different projections.
Now I would like to add some points, e.g. the cities included in geopandas
cities = gpd.read_file(gpd.datasets.get_path('naturalearth_cities'))
Unfortunately the cities are covered by the filled continents. Is there a way to get these cities in front or on top of the map?
My current code looks like this:
facecolor = 'sandybrown'
edgecolor = 'black'
ocean_color = '#A8C5DD'
crs1 = ccrs.NorthPolarStereo()
world = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))
cities = gpd.read_file(gpd.datasets.get_path('naturalearth_cities'))
w1 = world.to_crs(crs1.proj4_init)
c1 = cities.to_crs(crs1.proj4_init)
fig1, ax1 = plt.subplots(figsize=(7,7), subplot_kw={'projection': crs1})
# useful code to set map extent,
# --- if you want maximum extent, comment out the next line of code ---
ax1.set_extent([-60.14, 130.4, -13.12, -24.59], crs=ccrs.PlateCarree())
# at maximum extent, the circular bound trims map features nicely
ax1.add_geometries(w1['geometry'], crs=crs1, facecolor=facecolor, edgecolor=edgecolor, linewidth=0.5)
# this adds the ocean coloring
ax1.add_feature(cartopy.feature.OCEAN, facecolor=ocean_color, edgecolor='none')
# this adds the cities
c1.plot(ax=ax1, marker='o', color='red', markersize=50)
The result looks like this:
Upvotes: 0
Views: 1446
Reputation: 18812
The default drawing order for axes
is patches, lines, text. This order is determined by the zorder attribute.
Polygon/patch, zorder=1
Line 2D, zorder=2
Text, zorder=3
You can change the order for individual map features by setting the zorder
.
Any individual plot() call can set a value for the zorder of that particular item.
In your case, the code
c1.plot(ax=ax1, marker='o', color='red', markersize=50, zorder=20)
will plot the markers on top of all other features that have zorder
less than 20.
Zorder demo: https://matplotlib.org/gallery/misc/zorder_demo.html
Upvotes: 2