From dd6ad86656e4a6d4f573f34fe3d12bba3b27a35f Mon Sep 17 00:00:00 2001 From: Alexander Heger Date: Sat, 24 Aug 2019 23:02:39 +1000 Subject: [PATCH] fix for Basemap.pcolormesh 'ortho' projection --- lib/mpl_toolkits/basemap/__init__.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/mpl_toolkits/basemap/__init__.py b/lib/mpl_toolkits/basemap/__init__.py index d6dbcfbff..e9ade0ff1 100644 --- a/lib/mpl_toolkits/basemap/__init__.py +++ b/lib/mpl_toolkits/basemap/__init__.py @@ -3426,6 +3426,27 @@ def pcolormesh(self,x,y,data,**kwargs): if the dimensions are the same, then the last row and column of data will be ignored. """ ax, plt = self._ax_plt_from_kw(kwargs) + # fix for invalid grid points + if ((np.any(x > 1e20) or np.any (y > 1e20)) and + len(x.shape) == 2 and len(y.shape) == 2): + if not x.shape == y.shape: + raise Exception('pcolormesh: x and y need same dimension') + nx,ny = x.shape + if nx < data.shape[0] or ny < data.shape[1]: + raise Exception('pcolormesh: data dimension needs to be at least that of x and y.') + mask = ( + (x[:-1,:-1] > 1e20) | + (x[1:,:-1] > 1e20) | + (x[:-1,1:] > 1e20) | + (x[1:,1:] > 1e20) | + (y[:-1,:-1] > 1e20) | + (y[1:,:-1] > 1e20) | + (y[:-1,1:] > 1e20) | + (y[1:,1:] > 1e20) + ) + # we do not want to overwrite original array + data = data[:nx-1,:ny-1].copy() + data[mask] = np.nan self._save_use_hold(ax, kwargs) try: ret = ax.pcolormesh(x,y,data,**kwargs)