Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Draft
greglucas wants to merge2 commits intomatplotlib:main
base:main
Choose a base branch
Loading
fromgreglucas:quadmesh-point-in-poly

Conversation

greglucas
Copy link
Contributor

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.

importmatplotlib.pyplotaspltimportnumpyasnpn=4x=np.arange(n)X=x[:,None]*x[None, :]fig,ax=plt.subplots()mesh=ax.pcolormesh(X)mesh.set_mouseover(True)plt.show()

A concave mesh

importmatplotlib.pyplotaspltimportnumpyasnpx= [[0,-1], [1,0]]y= [[0,1], [1,-1]]fig,ax=plt.subplots()mesh=ax.pcolormesh(x,y, [[0]])mesh.set_mouseover(True)plt.show()

PR Checklist

Tests and Styling

  • Has pytest style unit tests (andpytest passes).
  • IsFlake 8 compliant (installflake8-docstrings and runflake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry indoc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented indoc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs shouldbuild without error).

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
Copy link
Member

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)?

Copy link
ContributorAuthor

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:

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?

Copy link
Member

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.

@jklymakjklymak marked this pull request as draftMay 24, 2022 11:02
@jklymak
Copy link
Member

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.

@greglucas
Copy link
ContributorAuthor

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)

@jklymak
Copy link
Member

Interesting idea! I'm not a huge user of this feature, so maybe@anntzer will have a comment....

@QuLogicQuLogic modified the milestones:v3.6.0,v3.7.0Aug 24, 2022
@QuLogicQuLogic modified the milestones:v3.7.0,v3.8.0Jan 7, 2023
@ksundenksunden modified the milestones:v3.8.0,future releasesAug 9, 2023
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@jklymakjklymakjklymak left review comments

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Projects
None yet
Milestone
future releases
Development

Successfully merging this pull request may close these issues.

4 participants
@greglucas@jklymak@QuLogic@ksunden

[8]ページ先頭

©2009-2025 Movatter.jp