-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
PERF: 3d draw speedups #30994
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
Draft
scottshambaugh
wants to merge
22
commits into
matplotlib:main
Choose a base branch
from
scottshambaugh:3d_draw_speed
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
PERF: 3d draw speedups #30994
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This fixes a long-standing issue where 3D plots ignored scale transforms. The methods set_xscale(), set_yscale(), set_zscale() existed but the transforms were never applied to data or coordinates. Key changes: - axes3d.py: Add _get_scaled_limits() to transform axis limits through scale transforms. Modify get_proj() to use scaled limits for world transformation. Override _update_transScale() to use identity transforms since 3D projection handles scales internally. Update autoscale_view() and _set_lim3d() to apply margins in transformed space. - art3d.py: Add _apply_scale_transforms() utility function. Update all do_3d_projection() methods to apply scale transforms before projection. - axis3d.py: Update _get_coord_info() to return scaled-space bounds. Modify _draw_ticks() to transform tick locations to scaled space. Update draw() and draw_grid() for proper coordinate handling. The fix ensures that: - Data coordinates are transformed through scale transforms before projection (e.g., log10 for log scale) - World transformation matrix maps scaled coordinates to unit cube - Axis ticks, labels, and grid lines position correctly - 2D display transforms remain linear (no double-transformation) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
25cb60c to
a00c89e
Compare
a00c89e to
077005f
Compare
4f6b42c to
9cee271
Compare
9cee271 to
2306d30
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Documentation: examples
files in galleries/examples
Performance
status: waiting for other PR
topic: mplot3d
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR summary
A collection of speedups for 3d plotting, from playing around with the py-spy profiler today.
_get_coord_infofromaxis3dtoaxes3d, since there's nothing axis-specific in itaxes3dcalculations that are used multiple times per draw by each axis:scaled_limits,bounds,transformed_cube, andcoord_info.axis._update_ticks()once per axis at start of draw, instead of multiple times in methodsWaiting on #30980 as a dependency. Diff to that is here:
https://github.com/matplotlib/matplotlib/compare/4ab0014840c3e86b3ca820dba7531857cb168ed6..scottshambaugh:3d_draw_speed
I measure a ~20-30% speedup when executing this script, which rotates the plot to execute 100 draws:
PR checklist