Xarray facetgrid map with cartopy produces unusable plot with certain dataset, projection and layout combinations

Viewed 259

I'm trying to make a facetgrid/"trellis" plot of netCDF data using xarray and cartopy. For most data, projection and layout combinations I've tried the output is reasonable.

However, in some cases, the maps appear as tiny blobs near the four corners of the plot, rendering the plot unreadable (see the image pr). I cannot reproduce this behaviour with the xarray tutorial dataset air_temperature.nc. Hence, I use a small sample from the gpcc precipitation dataset, in which the behaviour does occur. To produce this image, I used the following (hopefully near-minimal reproducible example):

# import required packages
import xarray as xr
import cartopy.crs as ccrs

# import included dataset from the directory where it is saved
file = "gpcc_sample.nc"
gpccrain = xr.open_dataarray(file)

# make the plot
proj = ccrs.PlateCarree() # the projection I'm using for the plot 
pl = gpccrain.plot(col="time", col_wrap=2, transform=proj,
                   subplot_kws={'projection': proj})

The above is adapted from this example in the xarray documentation. I suspect the problem may be related to this xarray issue on github; however the suggested fix no longer seems to apply since 'box-forced' is removed in Matplotlib 3.1 (see also: here). The problem does not occur without cartopy (i.e. with just gpccrain.plot(col="time", col_wrap=2)). I've tried providing reasonable values to the figsize and aspect arguments, to no avail. Removing the colorbar, altering the map extent to reasonable values (using ax.set_extent() in a for loop over the pl.axes.flat) or altering the cbar_kwargs also appears not to have a meaningful impact.

What should I change to get a reasonable plot?

I'm using xarray 0.16.1 and cartopy 0.18.0 on python 3.8.6 through anaconda.

Thank you in advance for any suggestions!

0 Answers
Related