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

plot_wireframe plotting speedup#29399

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 4, 2025
edited
Loading

PR summary

For large wireframe plots (in my testing, 8000x8000), a large chunk of time is spent doing autoscaling of the axes. There is some opportunity to vectorize these calculations and get speedups.

Changes here:

  1. Vectorize bounding box limits updates
  2. Faster array creation fortransforms.update_from_data_x andtransforms.update_from_data_y
  3. Switch from list comprehensions to vectorized approach foraxes3d.plot_wireframe. This also stores the data as a numpy array, which gives speedups when drawing.

The compiled functionupdate_path_extents is actually just about equal with a vectorized numpy approach speedwise when updating both x and y limits. But when doing single axis limits, it needs to check for NaNs for each pair of x or y, so the numpy approach lets you skip the extra x or y calculations and comes out ahead. This bit is a benefit for all 3D functions, not justplot_wireframe. I spent some time trying to refactor the compiled function to operate on just a single axis, but it's tricky to disentangle x and y. The numpy approach was easier and just as fast.

For my test case I'm seeing an average over 5 runs on main of 6.82 seconds, and on this PR 4.00 seconds - a 1.7x speedup.

importtimeimportnumpyasnpimportmatplotlib.pyplotaspltfig=plt.figure()ax=fig.add_subplot(111,projection='3d')x=y=np.linspace(-1,1,8000)X,Y=np.meshgrid(x,y)Z=X**2+Y**2print("Timing...")start_time=time.perf_counter()ax.plot_wireframe(X,Y,Z,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")

Plotting and drawing on main (avg 6.82 sec):
image

Plotting and drawing on this PR (avg 4.00 sec):
image

PR checklist

@scottshambaughscottshambaughforce-pushed theplot_wireframe_speedup branch 7 times, most recently fromea4a0dc todfe72edCompareJanuary 5, 2025 22:23
@scottshambaughscottshambaugh marked this pull request as ready for reviewJanuary 5, 2025 22:34
@scottshambaugh
Copy link
ContributorAuthor

CI failures are unrelated, merging

timhoffm reacted with thumbs up emoji

@scottshambaughscottshambaugh merged commitd08fd8f intomatplotlib:mainJan 8, 2025
37 of 40 checks passed
@anntzeranntzer mentioned this pull requestMar 29, 2025
5 tasks
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.

3 participants
@scottshambaugh@timhoffm@greglucas

[8]ページ先頭

©2009-2025 Movatter.jp