Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Backport PR #9723 on branch v2.1.x #9769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Backport PR #9723: ENH: Catch masked array and invalid x, y to pcolor…
…mesh
  • Loading branch information
tacaswell authored and MeeseeksDev[bot] committed Nov 13, 2017
commit b3f0c28894f400d0345a8925c64875ec1dfcd049
17 changes: 15 additions & 2 deletions 17 lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5172,7 +5172,21 @@ def _pcolorargs(funcname, *args, **kw):
return X, Y, C

if len(args) == 3:
X, Y, C = [np.asanyarray(a) for a in args]
# Check x and y for bad data...
C = np.asanyarray(args[2])
X, Y = [cbook.safe_masked_invalid(a) for a in args[:2]]
if funcname == 'pcolormesh':
if np.ma.is_masked(X) or np.ma.is_masked(Y):
raise ValueError(
'x and y arguments to pcolormesh cannot have '
'non-finite values or be of type '
'numpy.ma.core.MaskedArray with masked values')
# safe_masked_invalid() returns an ndarray for dtypes other
# than floating point.
if isinstance(X, np.ma.core.MaskedArray):
X = X.data # strip mask as downstream doesn't like it...
if isinstance(Y, np.ma.core.MaskedArray):
Y = Y.data
numRows, numCols = C.shape
else:
raise TypeError(
Expand Down Expand Up @@ -5567,7 +5581,6 @@ def pcolormesh(self, *args, **kwargs):
# convert to one dimensional arrays
C = C.ravel()
coords = np.column_stack((X, Y)).astype(float, copy=False)

collection = mcoll.QuadMesh(Nx - 1, Ny - 1, coords,
antialiased=antialiased, shading=shading,
**kwargs)
Expand Down
6 changes: 6 additions & 0 deletions 6 lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,12 @@ def test_pcolorargs():
ax.pcolormesh(x, y, Z[:-1, :-1], shading="gouraud")
with pytest.raises(TypeError):
ax.pcolormesh(X, Y, Z[:-1, :-1], shading="gouraud")
x[0] = np.NaN
with pytest.raises(ValueError):
ax.pcolormesh(x, y, Z[:-1, :-1])
x = np.ma.array(x, mask=(x < 0))
with pytest.raises(ValueError):
ax.pcolormesh(x, y, Z[:-1, :-1])


@image_comparison(baseline_images=['canonical'])
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.