Skip to content

Commit 59dc461

Browse files
authored
Merge pull request #476 from 2sn/master
fix for Basemap.pcolormesh 'ortho' projection
2 parents b9c161b + dd6ad86 commit 59dc461

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

lib/mpl_toolkits/basemap/__init__.py

+21
Original file line numberDiff line numberDiff line change
@@ -3431,6 +3431,27 @@ def pcolormesh(self,x,y,data,**kwargs):
34313431
if the dimensions are the same, then the last row and column of data will be ignored.
34323432
"""
34333433
ax, plt = self._ax_plt_from_kw(kwargs)
3434+
# fix for invalid grid points
3435+
if ((np.any(x > 1e20) or np.any (y > 1e20)) and
3436+
len(x.shape) == 2 and len(y.shape) == 2):
3437+
if not x.shape == y.shape:
3438+
raise Exception('pcolormesh: x and y need same dimension')
3439+
nx,ny = x.shape
3440+
if nx < data.shape[0] or ny < data.shape[1]:
3441+
raise Exception('pcolormesh: data dimension needs to be at least that of x and y.')
3442+
mask = (
3443+
(x[:-1,:-1] > 1e20) |
3444+
(x[1:,:-1] > 1e20) |
3445+
(x[:-1,1:] > 1e20) |
3446+
(x[1:,1:] > 1e20) |
3447+
(y[:-1,:-1] > 1e20) |
3448+
(y[1:,:-1] > 1e20) |
3449+
(y[:-1,1:] > 1e20) |
3450+
(y[1:,1:] > 1e20)
3451+
)
3452+
# we do not want to overwrite original array
3453+
data = data[:nx-1,:ny-1].copy()
3454+
data[mask] = np.nan
34343455
self._save_use_hold(ax, kwargs)
34353456
try:
34363457
ret = ax.pcolormesh(x,y,data,**kwargs)

0 commit comments

Comments
 (0)