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

Skip to content

Commit 80550e1

Browse files
authored
Merge pull request #18398 from greglucas/warn_pcolorargs
Warn on non-increasing/decreasing pcolor coords
2 parents f24a1e2 + 75cb810 commit 80550e1

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5576,6 +5576,15 @@ def _interp_grid(X):
55765576
# helper for below
55775577
if np.shape(X)[1] > 1:
55785578
dX = np.diff(X, axis=1)/2.
5579+
if not (np.all(dX >= 0) or np.all(dX <= 0)):
5580+
cbook._warn_external(
5581+
f"The input coordinates to {funcname} are "
5582+
"not all either increasing or decreasing, "
5583+
"the automatically computed edges can "
5584+
"produce misleading results in this case. "
5585+
"It is recommended to supply the "
5586+
f"quadrilateral edges to {funcname}"
5587+
f" yourself. See help({funcname}).")
55795588
X = np.hstack((X[:, [0]] - dX[:, [0]],
55805589
X[:, :-1] + dX,
55815590
X[:, [-1]] + dX[:, [-1]]))

lib/matplotlib/tests/test_axes.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,13 @@ def test_pcolorargs():
11751175
x = np.ma.array(x, mask=(x < 0))
11761176
with pytest.raises(ValueError):
11771177
ax.pcolormesh(x, y, Z[:-1, :-1])
1178+
# Expect a warning with non-increasing coordinates
1179+
x = [359, 0, 1]
1180+
y = [-10, 10]
1181+
X, Y = np.meshgrid(x, y)
1182+
Z = np.zeros(X.shape)
1183+
with pytest.warns(UserWarning, match="The input coordinates"):
1184+
ax.pcolormesh(X, Y, Z, shading='auto')
11781185

11791186

11801187
@check_figures_equal(extensions=["png"])

0 commit comments

Comments
 (0)