-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
QuadMesh point in poly #22955
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
base: main
Are you sure you want to change the base?
QuadMesh point in poly #22955
Conversation
This adds a contains function to QuadMesh that implements a point-in-poly winding number calculation. It scales linearly with the size of the mesh, but is vectorized to use numpy arrays for computations. It handles concave and convex quads.
@@ -2195,11 +2195,45 @@ def draw(self, renderer): | |||
renderer.close_group(self.__class__.__name__) | |||
self.stale = False | |||
|
|||
def contains(self, event): | |||
# docstring inherited |
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.
is there a way to fast-path the often-used pcolormesh case of a rectilinear grid (lat and lon are each 1-d)?
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.
Sort-of. I'm not sure it is doable in QuadMesh currently because it is so flexible with the mesh coordinates, so somehow we would need to store some information about what x/y grid was passed in. That case is already handled in PcolorImage though:
matplotlib/lib/matplotlib/image.py
Lines 1318 to 1329 in cb8680f
def get_cursor_data(self, event): | |
# docstring inherited | |
x, y = event.xdata, event.ydata | |
if (x < self._Ax[0] or x > self._Ax[-1] or | |
y < self._Ay[0] or y > self._Ay[-1]): | |
return None | |
j = np.searchsorted(self._Ax, x) - 1 | |
i = np.searchsorted(self._Ay, y) - 1 | |
try: | |
return self._A[i, j] | |
except IndexError: | |
return None |
(also note that I still get quite good performance for 400x400 size meshes which is already pretty small boxes for investigating coordinate output)
Thinking about this more generally, I wonder if we could consolidate some of these pcolor-style plots into a more generic Collection that would defer choosing which one of PcolorImage/QuadMesh/PolyCollection to draw until the very end, but leaving all of the options available. For instance, if someone wants shading=gouraud
we would choose QuadMesh for the rendering. I think this was sort of the idea behind pcolorfast()
(?), but that will return different collections depending on what the input is, which may be somewhat confusing for modifying properties later?
Moved to draft pending rebase. This seems reasonable to me if you say it really helps things. Doesn't particularly help the slowness of the cursor for large pcolormesh to the point where I think the cursor display should be on by default. |
All reactions
Sorry, something went wrong.
I'm not in any rush to get this in and I agree that it doesn't completely help the cursor issue. Thinking about the slow cursor issue, I wonder if it would be helpful to set the mouseover state based on an arbitrary size of the QuadMesh so that the smaller meshes do get it available by default. if coords.size > 500:
self.set_mouseover(False) |
All reactions
Sorry, something went wrong.
Interesting idea! I'm not a huge user of this feature, so maybe @anntzer will have a comment.... |
All reactions
Sorry, something went wrong.
jklymak
At least 1 approving review is required to merge this pull request.
Successfully merging this pull request may close these issues.
PR Summary
This adds a point-in-quad function to the QuadMesh collection, implemented with Numpy rather than generating all of the paths and passing into Agg's point in poly check.
Change n to check the performance. This still struggles with a 1000 x 1000 mesh for me, but I'm not sure that we can really expect this to scale for generic meshes.
A concave mesh
PR Checklist
Tests and Styling
pytest
passes).flake8-docstrings
and runflake8 --docstring-convention=all
).Documentation
doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).