Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.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 ourterms of service andprivacy 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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This adds a contains function to QuadMesh that implements apoint-in-poly winding number calculation. It scales linearlywith the size of the mesh, but is vectorized to use numpyarrays 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 incb8680f
defget_cursor_data(self,event): | |
# docstring inherited | |
x,y=event.xdata,event.ydata | |
if (x<self._Ax[0]orx>self._Ax[-1]or | |
y<self._Ay[0]ory>self._Ay[-1]): | |
returnNone | |
j=np.searchsorted(self._Ax,x)-1 | |
i=np.searchsorted(self._Ay,y)-1 | |
try: | |
returnself._A[i,j] | |
exceptIndexError: | |
returnNone |
(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 wantsshading=gouraud
we would choose QuadMesh for the rendering. I think this was sort of the idea behindpcolorfast()
(?), but that will returndifferent collections depending on what the input is, which may be somewhat confusing for modifying properties later?
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 in general unifying the three pcolor methods would be great - I am personally not a fan of different ones for different purposes; in general if there is a performance issue, one just rasterizes anyhow and performance is usually more than adequate.
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. |
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. ifcoords.size>500:self.set_mouseover(False) |
Interesting idea! I'm not a huge user of this feature, so maybe@anntzer will have a comment.... |
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).