Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 669f9ac

Browse files
authored
Merge pull request #27773 from jklymak/mnt-pcolormesh-robust-underflow
2 parents 402f41f + 793f1df commit 669f9ac

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5883,7 +5883,7 @@ def _pcolorargs(self, funcname, *args, shading='auto', **kwargs):
58835883
def _interp_grid(X):
58845884
# helper for below
58855885
if np.shape(X)[1] > 1:
5886-
dX = np.diff(X, axis=1)/2.
5886+
dX = np.diff(X, axis=1) * 0.5
58875887
if not (np.all(dX >= 0) or np.all(dX <= 0)):
58885888
_api.warn_external(
58895889
f"The input coordinates to {funcname} are "

lib/matplotlib/tests/test_axes.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,19 @@ def test_pcolorargs():
15171517
ax.pcolormesh(X, Y, Z, shading='auto')
15181518

15191519

1520+
def test_pcolormesh_underflow_error():
1521+
"""
1522+
Test that underflow errors don't crop up in pcolormesh. Probably
1523+
a numpy bug (https://github.com/numpy/numpy/issues/25810).
1524+
"""
1525+
with np.errstate(under="raise"):
1526+
x = np.arange(0, 3, 0.1)
1527+
y = np.arange(0, 6, 0.1)
1528+
z = np.random.randn(len(y), len(x))
1529+
fig, ax = plt.subplots()
1530+
ax.pcolormesh(x, y, z)
1531+
1532+
15201533
def test_pcolorargs_with_read_only():
15211534
x = np.arange(6).reshape(2, 3)
15221535
xmask = np.broadcast_to([False, True, False], x.shape) # read-only array

0 commit comments

Comments
 (0)