diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 500ef4365092..ff03cc752a06 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -5682,6 +5682,15 @@ def _interp_grid(X): # helper for below if np.shape(X)[1] > 1: dX = np.diff(X, axis=1)/2. + if not (np.all(dX >= 0) or np.all(dX <= 0)): + cbook._warn_external( + f"The input coordinates to {funcname} are " + "not all either increasing or decreasing, " + "the automatically computed edges can " + "produce misleading results in this case. " + "It is recommended to supply the " + f"quadrilateral edges to {funcname}" + f" yourself. See help({funcname}).") X = np.hstack((X[:, [0]] - dX[:, [0]], X[:, :-1] + dX, X[:, [-1]] + dX[:, [-1]])) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index a35f55a55db9..4b4775454d28 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -1131,6 +1131,13 @@ def test_pcolorargs(): x = np.ma.array(x, mask=(x < 0)) with pytest.raises(ValueError): ax.pcolormesh(x, y, Z[:-1, :-1]) + # Expect a warning with non-increasing coordinates + x = [359, 0, 1] + y = [-10, 10] + X, Y = np.meshgrid(x, y) + Z = np.zeros(X.shape) + with pytest.warns(UserWarning, match="The input coordinates"): + ax.pcolormesh(X, Y, Z, shading='auto') @check_figures_equal(extensions=["png"])