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
Do not add padding to 3D axis limits when limits are manually set #25272
base: main
Are you sure you want to change the base?
Conversation
Although I think that this is really how it should be, the question is if we can just enforce it or if there should be a deprecation path? Better ping in @timhoffm directly... |
56f5c0e
to
eb13ba8
Compare
This is changing intended behavior in some of the tests so some tweaking to do, but should be enough here right now to get an idea. |
Talked about this in the dev call today, consensus was to make the new behavior default without deprecation, but add an rc_param to switch back to current behavior. |
ba17fca
to
164a811
Compare
164a811
to
9ed0c5b
Compare
3200e54
to
2239207
Compare
40fc8f0
to
1c04693
Compare
Well, it looks like the floating point theory is likely correct, because the tests are all passing on my machine, and the different CI platforms are having different tests throw image comparison errors. What's the proper way to handle this? Loosen the image comparison tolerance? I'm not sure how to examine the test images from the different CI environments if I can't recreate the issue locally. |
00f03ca
to
43f7d59
Compare
The ideal way is to add platform-specific margins, like: matplotlib/lib/matplotlib/tests/test_lines.py Lines 187 to 189 in e7fd79f
I think one way to make it at least slightly better is to pre-compute the constants. In this way one error source is removed and the code will execute slightly faster. Always possible to use a comment to illustrate where it comes from. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the constants should be pre-computed I think.
Doc-strings should typically have a single-sentence/line description (hence, the need for an empty line after).
A change note is required for the new rcParam
I think the purpose of the PR is for sure worthwhile, but I do not know enough to have any real comments on the implentation.
#axes3d.grid: True # display grid on 3D axes | ||
#polaraxes.grid: True # display grid on polar axes | ||
#axes3d.grid: True # display grid on 3D axes | ||
#axes3d.automargin: False # automatically add margin when manually setting 3D axis limits |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not fully get if this or "classic" should be True/False, but shouldn't they be different?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I follow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I am not interpreting "classic" correctly, but I was just thinking that "classic" possibly should have automargin=True
, to preserve the "classic" style?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is 'classic' the default? I'm struggling to find where else the default style is stored. Per the comment up above that we want to "make the new behavior default without deprecation", I agree it makes sense if this is a style the user has to apply, but not if it actually is the default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think classic is pre-2.0 (as there is an mpl20 style). But will see if I can dig it up.
b55d12c
to
978889b
Compare
Thank you for the thorough review @oscargus! To give some context for where these constants are coming from, the original behavior when generating the view limits for 3d plots was fairly broken. There was always 1/48 of the axis range added to either side of the axis bounds when drawing the axes, however this extra "view margin" was purely visual. The calculations for the zoom level for the plot, which grid/tick lines to show, and several other spots in the code all used the non-padded axis limits for their calculation. So, when I converted the backed to use the actual axis limits everywhere, this required putting in a lot of scale factors to keep the visual appearance ( |
978889b
to
415763e
Compare
fb58c8a
to
39637c8
Compare
I dug into the scale factor more after your comment, and changing two of them to 24/25 made all the baseline images pass without updates! Reduces the size of this MR quite a bit, thank you! I'll note however that the scale factor in ticker I left at 23/24, because 24/25 was causing an image failure for gridline locations on one of the tests. I'm not quite sure what to make of that, but I do think it's plausibly correct. |
39637c8
to
545cd60
Compare
93e4d09
to
e5f19a0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure these comments really explain why 24/25, etc.
More test images Images Test new scaling factor Test new scaling factor Test for exact limits
Co-authored-by: Elliott Sales de Andrade <[email protected]>
dc4427c
to
69f3a08
Compare
@QuLogic do you mean the comments in the code, or in this thread? I'm not quite sure how to concisely describe the scale factors in more detail, as they are rather magic-constanty and I figured them out 50/50 by understanding the code and trial-and-error. |
I mean the comments in the code. Saying |
Essentially - the old padding was 1/48, and was applied 2x (to the min and max limits), so that's where the 1 ± 1/24 scaling came from. The old padding was from these lines: https://github.com/matplotlib/matplotlib/blob/fff2a79ce22ab39bea95067d30438bfdbe47f560/lib/mpl_toolkits/mplot3d/axis3d.py#L230_L232 deltas = (maxs - mins) / 12
mins -= 0.25 * deltas
maxs += 0.25 * deltas I generally like to err on the side of too much detail in comments, but am happy to take out the extra fractions in the code if you think it's going to be confusing for people. |
PR Summary
Closes #18052
Before:

After (exact limits for x and y, z retains default padded limits):

There are a ton of test image changes, gonna be a hefty commit.PR Checklist
Documentation and Tests
pytest
passes)Release Notes
.. versionadded::
directive in the docstring and documented indoc/users/next_whats_new/
.. versionchanged::
directive in the docstring and documented indoc/api/next_api_changes/
next_whats_new/README.rst
ornext_api_changes/README.rst