Skip to content

Commit dd6ad86

Browse files
committed
fix for Basemap.pcolormesh 'ortho' projection
1 parent a551c23 commit dd6ad86

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

lib/mpl_toolkits/basemap/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3426,6 +3426,27 @@ def pcolormesh(self,x,y,data,**kwargs):
34263426
if the dimensions are the same, then the last row and column of data will be ignored.
34273427
"""
34283428
ax, plt = self._ax_plt_from_kw(kwargs)
3429+
# fix for invalid grid points
3430+
if ((np.any(x > 1e20) or np.any (y > 1e20)) and
3431+
len(x.shape) == 2 and len(y.shape) == 2):
3432+
if not x.shape == y.shape:
3433+
raise Exception('pcolormesh: x and y need same dimension')
3434+
nx,ny = x.shape
3435+
if nx < data.shape[0] or ny < data.shape[1]:
3436+
raise Exception('pcolormesh: data dimension needs to be at least that of x and y.')
3437+
mask = (
3438+
(x[:-1,:-1] > 1e20) |
3439+
(x[1:,:-1] > 1e20) |
3440+
(x[:-1,1:] > 1e20) |
3441+
(x[1:,1:] > 1e20) |
3442+
(y[:-1,:-1] > 1e20) |
3443+
(y[1:,:-1] > 1e20) |
3444+
(y[:-1,1:] > 1e20) |
3445+
(y[1:,1:] > 1e20)
3446+
)
3447+
# we do not want to overwrite original array
3448+
data = data[:nx-1,:ny-1].copy()
3449+
data[mask] = np.nan
34293450
self._save_use_hold(ax, kwargs)
34303451
try:
34313452
ret = ax.pcolormesh(x,y,data,**kwargs)

0 commit comments

Comments
 (0)