8000 Backport PR #18398: Warn on non-increasing/decreasing pcolor coords · matplotlib/matplotlib@257a689 · GitHub
[go: up one dir, main page]

Skip to content

Commit 257a689

Browse files
dopplershiftmeeseeksmachine
authored andcommitted
Backport PR #18398: Warn on non-increasing/decreasing pcolor coords
1 parent 254f062 commit 257a689

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
@@ -5630,6 +5630,15 @@ def _interp_grid(X):
56305630
# helper for below
56315631
if np.shape(X)[1] > 1:
56325632
dX = np.diff(X, axis=1)/2.
5633+
if not (np.all(dX >= 0) or np.all(dX <= 0)):
5634+
cbook._warn_external(
5635+
f"The input coordinates to {funcname} are "
5636+
"not all either increasing or decreasing, "
5637+
"the automatically computed edges can "
5638+
"produce misleading results in this case. "
5639+
"It is recommended to supply the "
5640+
f"quadrilateral edges to {funcname}"
5641+
f" yourself. See help({funcname}).")
56335642
X = np.hstack((X[:, [0]] - dX[:, [0]],
56345643
X[:, :-1] + dX,
56355644
X[:, [-1]] + dX[:, [-1]]))

lib/matplotlib/tests/test_axes.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,13 @@ def test_pcolorargs():
11621162
x = np.ma.array(x, mask=(x < 0))
11631163
with pytest.raises(ValueError):
11641164
ax.pcolormesh(x, y, Z[:-1, :-1])
1165+
# Expect a warning with non-increasing coordinates
1166+
x = [359, 0, 1]
1167+
y = [-10, 10]
1168+
X, Y = np.meshgrid(x, y)
1169+
Z = np.zeros(X.shape)
1170+
with pytest.warns(UserWarning, match="The input coordinates"):
1171+
ax.pcolormesh(X, Y, Z, shading='auto')
11651172

11661173

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

0 commit comments

Comments
 (0)
0