13

I am trying to plot position of several points (scatter plot) on a map using Cartopy (see code below). When I try to render the plot, data-points are rendered behind LAND-layer. But I want to plot my scatter-data over LAND-layer... What I am doing wrong?

Cartopy: ver. 0.12.x, Matplotlib: ver.1.4.2

import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature 

ax = plt.axes(projection=ccrs.PlateCarree()) 
ax.set_extent([125, 150, 35, 63])         

ax.stock_img()

ax.add_feature(cfeature.LAND) #If I comment this => all ok, but I need 
ax.add_feature(cfeature.LAKES)
ax.add_feature(cfeature.RIVERS)
ax.coastlines()

ax.scatter(yc,xc,transform=ccrs.PlateCarree()) #yc, xc -- lists or numpy arrays

plt.show()

Points shown under the LAND layer

Plot without LAND-layer

bubble
  • 1,634
  • 12
  • 17

1 Answers1

14

Most, if not all, matplotlib plotting functions take a zorder parameter to specify the drawing order.

Lower zorders will be drawn first, and as such higher zorders will appear "on top".

So yeah, pass in zorder=xxx to arrange your layers.

Paul H
  • 65,268
  • 20
  • 159
  • 136
  • 1
    @pelson or @paul-h - I'm just curious, but why is this case? Sort of intuitively I would expect the scatter points to be 'on top' if the `plt.scatter` call is after the `ax.add_feature` calls. I had a similar problem to the OP and have to specify `zorder=2`. – decvalts Apr 23 '18 at 11:05
  • 1
    @decvalts I couldn't tell you without inspecting the cartopy source code to check what the default zorders are. I don't have time for that, so I'll encourage you to do so. – Paul H Apr 23 '18 at 21:04