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

Skip to content

Warn on non-increasing/decreasing pcolor coords #18398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After writing the PR. Maybe "sorted" is a better word to use here? I'm open to suggestions about the text.

"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]]))
Expand Down
7 changes: 7 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down