Skip to content

MNT: Commonize 3D zmargin handling with x and y axes#31287

Open
scottshambaugh wants to merge 2 commits intomatplotlib:mainfrom
scottshambaugh:3d_zmargin
Open

MNT: Commonize 3D zmargin handling with x and y axes#31287
scottshambaugh wants to merge 2 commits intomatplotlib:mainfrom
scottshambaugh:3d_zmargin

Conversation

@scottshambaugh
Copy link
Copy Markdown
Contributor

@scottshambaugh scottshambaugh commented Mar 12, 2026

PR summary

Closes #31213

The 3D z axis margin was handled inconsistently from the x and y axes, leading to special casing and inconsistent visual results even with equal values for the axes.[x/y/z]margin rcparams. I put this change somewhere between maintenance and a bugfix.

This requires regenerating a good number of baseline images (about half of 3d images), but I don't see a good way around that.

If people don't like the results being "squished" then the right way to handle this would be to keep these changes and set axes.zmargin = 0 in the rcparams (scatter plots and nonlinear scales would still change appearance). There's some justification for this because the x:y:z aspect ratio is 4:4:3 by default, so that would be "unsquishing" in a way. But this is always controllable by the user via set_box_aspect and axis limits. I don't feel too strongly either way.

AI Disclosure

PR checklist

@scottshambaugh scottshambaugh force-pushed the 3d_zmargin branch 3 times, most recently from ac5e4d3 to b4732a8 Compare March 12, 2026 02:54
@scottshambaugh scottshambaugh marked this pull request as draft March 12, 2026 04:36
Comment thread lib/mpl_toolkits/mplot3d/axes3d.py Outdated
@scottshambaugh scottshambaugh force-pushed the 3d_zmargin branch 4 times, most recently from a12522b to f01afb5 Compare March 13, 2026 00:48
@scottshambaugh scottshambaugh marked this pull request as ready for review March 13, 2026 00:49
@QuLogic
Copy link
Copy Markdown
Member

QuLogic commented Mar 14, 2026

I'm pretty sure many of these tests that are changed here have a "Remove this line when the image is regenerated." comment in them that should be heeded.

@scottshambaugh
Copy link
Copy Markdown
Contributor Author

scottshambaugh commented Mar 14, 2026

Good catch, took those off of the 5 that had it. Also took off the tolerance on one, I'll see if it needs to be added back after cross-platform CI.

Edit: looks good

@QuLogic
Copy link
Copy Markdown
Member

QuLogic commented Mar 17, 2026

I haven't checked, but I'm not sure if some of these changes will conflict with the text overhaul branch? I guess we need some decision on some of the questions in the original post though.

@QuLogic QuLogic added the status: needs comment/discussion needs consensus on next step label Mar 17, 2026
@scottshambaugh
Copy link
Copy Markdown
Contributor Author

scottshambaugh commented Mar 19, 2026

Some images will need to be regenerated but I don't see the code changes conflicting with text edits.

To summarize, the choice that needs to be made is between these. (1) is what's in right now, but I don't care too much either way:

  1. Keep existing 0.05 margins on all axes, understanding that this will "squish" most 3D plot types in Z
  2. Move the Z margin to 0 to keep most plot types looking the same (though scatter plots will still change since they were being forced to a minimum of 0.05)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MNT]: 3D z axis margin is handled differently than x and z

2 participants