-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix handling single contour level out of data range #17179
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
Conversation
Previously, the behavior of ContourSet was special when a single contour level was specified that was out of range of the given z array. In that case, instead of the given value the minimum of the dataset was contoured, instead. This is very unexpected, in my opinion. This simple change simply makes no contour line at all, instead.
Since there aren't any levels, would it be possible to just set it to an empty list? |
That is what I initially tried, but this seems to break some assumptions elsewhere. If I set test.py:
produces this error
The observation was that with |
This PR could use a little more explanation and motivating example. It seems like maybe its reasonable, but its an API change to change the returned type, so it'll need some justification and tests. Also what does this proposed change do to colorbars that are attached to the contour? I'll guess they don't like the NaN, but I've not tested. Also, what is the use case that needs this fixed? |
Colorbars do not work in this case, even without my patch: test_colorbar.py:
produces
|
This still seems useful, but needs more work... |
The example given in #17179 (comment) is now fixed on the Matplotlib main branch - I'm not sure when or how it was fixed, but given that I'm going to close this PR. If I've got anything wrong there please shout and we can re-open! |
I haven't read in detail, but I think #24912 might be the relevant fix. |
PR Summary
Previously, the behavior of ContourSet was special when a single contour
level was specified that was out of range of the given z array.
In that case, instead of the given value the minimum of the dataset was
contoured, instead. This is very unexpected, in my opinion.
This simple change simply makes no contour line at all, instead.
PR Checklist
The change is so simple and small, I believe none of the entries in the checklist is really applicable. I tested, of course, that with
[np.nan]
in placeplt.contour()
still works. I am unsure, however, in what other places that change could have unintended side-effects, so I would be glad for some review.