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

3D plotting performance improvements#29397

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

Merged

Conversation

scottshambaugh
Copy link
Contributor

@scottshambaughscottshambaugh commentedJan 3, 2025
edited
Loading

PR summary

This builds off of#16688, to rebase off of main, extend as applicable to all the 3D object types, and allow for compatibility with the new 3D axlim clipping. With the test code below, I am seeing substantial speedups in draw times for some types of plots.

Closes#16659

importtimeimportnumpyasnpimportmatplotlib.pyplotaspltfig,ax=plt.subplots(subplot_kw={"projection":"3d"})x=y=np.linspace(-1,1,100)X,Y=np.meshgrid(x,y)Z=X**2+Y**2print("Timing...")start_time=time.perf_counter()#ax.plot_surface(X, Y, Z, rstride=1, cstride=1, axlim_clip=False)#ax.scatter(x, y, np.ones_like(x), axlim_clip=False)ax.plot_wireframe(X,Y,Z,axlim_clip=False)#ax.bar3d(X.ravel(), Y.ravel(), 0, 0.01, 0.01, 1, axlim_clip=False)ax.set_xlim(0,1)fig.canvas.draw()end_time=time.perf_counter()plt.close()print(f"Time taken:{end_time-start_time:.4f} seconds")
functionobjectdraw time mainthis PRimprovement
plot_surface (400x400)Poly3DCollection16.55 sec1.86 sec8.9x
scatter (100000)Path3DCollection3.65 sec3.22 sec1.1x
plot wireframe (8000x8000)Line3DCollection2.72 sec1.39 sec2.0x
bard3d (100x100)Patch3DCollection7.17 sec2.02 sec3.5x

PR checklist

Illviljan reacted with rocket emoji
@scottshambaugh
Copy link
ContributorAuthor

scottshambaugh commentedJan 5, 2025
edited
Loading

Thoughts on if the 3D speedups warrant a what's new?

@timhoffm
Copy link
Member

Thoughts on if the 3D speedups warrant a what's new?

Since these are substantial, I‘d say yes.

scottshambaugh reacted with thumbs up emoji

@scottshambaughscottshambaugh changed the title3D masked array performance improvements3D plotting performance improvementsJan 6, 2025
# Some faces might contain masked vertices, so we want to ignore any
# errors that those might cause
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Should these errors be handled within the_proj_transform_vectors case directly closer to where these errors would actually arise? I know there has been some work in numpy to not raise invalid/division warnings on masked elements, so is this still an issue now?

Copy link
ContributorAuthor

@scottshambaughscottshambaughJan 7, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I removed the error ignore line and did not see any issues. The tests cover partially masked Poly3DCollections, so that case is exercised, and it looks like the improved masked handling covers any previous errors here.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Looks like the error does crop up in the AppVeyor build, so adding the original error suppression back in. I don't want to put it in_proj_transform_vectors since it might not always be the case that we know that we have masked out the problematic vertices outside of that function.

Copy link
Contributor

@greglucasgreglucas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think this is a really great performance improvement and shows how much of an impact numpy vectorization can have. Just a few minor nits that you can take or leave.

@scottshambaughscottshambaughforce-pushed themasked_array_performance branch 2 times, most recently fromf6356c0 to14e26f9CompareJanuary 8, 2025 18:12
@timhoffmtimhoffm merged commit29f3a5c intomatplotlib:mainJan 28, 2025
40 of 41 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@timhoffmtimhoffmtimhoffm approved these changes

@greglucasgreglucasgreglucas approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.11.0
Development

Successfully merging this pull request may close these issues.

Speeding up Axes3D.plot_surface 4-8x
3 participants
@scottshambaugh@timhoffm@greglucas

[8]ページ先頭

©2009-2025 Movatter.jp