Open joshdorrington opened 4 years ago
I have just noted that this is a problem with the contourf function, but does not occur when using pcolormesh:
projs=[ccrs.PlateCarree(),ccrs.Mollweide(),\
ccrs.Orthographic(0,90),ccrs.NearsidePerspective(central_latitude=50,central_longitude=-20)]
for i,proj in enumerate(projs):
ax=plt.subplot(4,1,i+1,projection=proj)
ax.coastlines()
plot=iplt.pcolormesh(cube, cmap=plt.cm.RdBu_r,axes=ax)
plt.colorbar(mappable=plot)
I'm pretty sure this is the same issue as https://github.com/SciTools/cartopy/issues/1076 where one of the contour levels is essentially covering up the rest of the underlying contours and not being clipped properly. There is a proposed fix linked in a PR at the bottom of that issue.
Here is a reproducer without Iris:
import matplotlib.pyplot as plt
import cartopy
import cartopy.util
import cartopy.crs as ccrs
import numpy as np
from xarray import open_dataset
print(cartopy.__version__)
ds = open_dataset('testcube.nc')
da = ds.unknown
data, lons, lats = cartopy.util.add_cyclic(da.data, x=da.longitude.data, y=da.latitude.data)
clevs=np.linspace(-abs(da.data).max(),abs(da.data).max(),21)
projs=[ccrs.PlateCarree(),ccrs.Mollweide(),ccrs.Orthographic(0,90),ccrs.NearsidePerspective(central_latitude=50,central_longitude=-20)]
for i,proj in enumerate(projs):
ax=plt.subplot(4,1,i+1,projection=proj)
ax.coastlines()
plot=ax.contourf(lons, lats, data, levels=clevs, cmap=plt.cm.RdBu_r, transform=ccrs.PlateCarree())
plt.colorbar(mappable=plot)
plt.show()
I am trying to plot a netcdf file, which can be found here: testcube.zip
The issue is that the Orthographic projection incorrectly plots the data. Seemingly, all negative values are set to 0 during plotting. This is not the case for other projections. My code is below:
Code to reproduce
Which produces the following output: