Skip to content

Commit

Permalink
Merge pull request #27773 from jklymak/mnt-pcolormesh-robust-underflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ksunden committed Feb 12, 2024
2 parents 402f41f + 793f1df commit 669f9ac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5883,7 +5883,7 @@ def _pcolorargs(self, funcname, *args, shading='auto', **kwargs):
def _interp_grid(X):
# helper for below
if np.shape(X)[1] > 1:
dX = np.diff(X, axis=1)/2.
dX = np.diff(X, axis=1) * 0.5
if not (np.all(dX >= 0) or np.all(dX <= 0)):
_api.warn_external(
f"The input coordinates to {funcname} are "
Expand Down
13 changes: 13 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,19 @@ def test_pcolorargs():
ax.pcolormesh(X, Y, Z, shading='auto')


def test_pcolormesh_underflow_error():
"""
Test that underflow errors don't crop up in pcolormesh. Probably
a numpy bug (https://github.com/numpy/numpy/issues/25810).
"""
with np.errstate(under="raise"):
x = np.arange(0, 3, 0.1)
y = np.arange(0, 6, 0.1)
z = np.random.randn(len(y), len(x))
fig, ax = plt.subplots()
ax.pcolormesh(x, y, z)


def test_pcolorargs_with_read_only():
x = np.arange(6).reshape(2, 3)
xmask = np.broadcast_to([False, True, False], x.shape) # read-only array
Expand Down

0 comments on commit 669f9ac

Please sign in to comment.