Search code examples
pythonmatplotlibpython-xarraycartopy

ValueError when displaying cartopy facet-grid map with NaN values in xarray


I was trying to display seasonal facet grid map using xarray with NaN values (for sea regions) with this code:

ds = xr.open_dataset("../data/full_data_monthly_v2018_025.nc")
prKepri = ds['precip'].sel(lat = slice(-0.49, -4.7), lon = slice(103.37, 109.1))
data = prKepri.groupby('time.season').mean(dim='time', skipna = False)
proj = ccrs.PlateCarree()
p = data.plot(col = 'season', robust = True, cmap = 'magma_r', col_wrap =2,
             subplot_kws=dict(projection=proj), transform=ccrs.PlateCarree())
for ax in p.axes.flat:
    ax.coastlines();

then xarray raised me an error:

ValueError: zero-size array to reduction operation minimum which has no identity

I try to use skipna = False argument. But the problem still persisted. I use GPCC reanalysis data: https://opendata.dwd.de/climate_environment/GPCC/full_data_2018/full_data_monthly_v2018_025.nc.gz.

I use xarray v 0.16.0


Solution

  • This is a bug in matplotlib 3.3.1 that causes problems with CartoPy 0.18. Until matplotlib 3.3.2 is released, the easiest work-around is likely to install matplotlib 3.3.0.