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
Fixed bug in find_nearest_contour #22767
Fixed bug in find_nearest_contour #22767
Conversation
c51aeef
to
55d98a7
Compare
Power cycling to trigger the tests. |
I think this PR is ready for further review. Let me know if any changes need to be made to the testing. |
lib/matplotlib/contour.py
Outdated
@@ -1371,7 +1371,7 @@ def find_nearest_contour(self, x, y, indices=None, pixel=True): | |||
# Nonetheless, improvements could probably be made. | |||
|
|||
if indices is None: | |||
indices = range(len(self.levels)) | |||
indices = range(len(self.layers)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a slight preference to change this to
indices = range(len(self.layers)) | |
indices = range(len(self.collections)) |
as that is the data structure that we need to match?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this change makes sense. I outlined some issues below that I'd like you to look at.
I have not chased this through enough to answer this my self, but is this method implemented in a way that makes sense for filled contours? With line contours you know that each path is at the same level and lines never intersect. With a filled contour the whole patch is "at the same level" with discontinuities at the boundaries (that is there are two patches that share and edge that are different values). In the case of filled shouldn't we be saying "which collection does this fall in?" instead? |
55d98a7
to
6eea6e6
Compare
If this function should only support #22762 highlights that currently, when the function is called on |
Sorry, didn't see @tacaswell's additional questions; I won't merge until he's satisfied with the answers. |
I am not sure what use there is in choosing the nearest "contour" on a filled contour. My tendency would be to raise on contourf collections and if users need to know the "nearest contour" they can make an unfilled contour to go with the filled one (perhaps hiding it if they don't want itvnisually there). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The consensus of the discussion is that the correct fix here is to :
- document that this only works on unfilled contours
- make it raise a better error on filled contours
I agree with the consensus! Thanks for all of the input. I will make these changes soon. I need to get through a few other things first. |
ec55df9
to
f8a80f7
Compare
f8a80f7
to
4a47543
Compare
Completely different approach now.
@meeseeksdev backport to v3.5.x |
…767-on-v3.5.x Backport PR #22767 on branch v3.5.x (Fixed bug in find_nearest_contour)
PR Summary
The find_nearest_contour function was defined incorrectly. I fixed the bug and added a simple test, based on the original issues test.
Thank you @jhelmboldt for finding this issue and offering a solution to it.
Closes #22762
PR Checklist
Tests and Styling
pytest
passes).flake8-docstrings
and runflake8 --docstring-convention=all
).