Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FIX: adjust_bbox should not modify layout engine #24971

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

Merged
merged 1 commit into from
Jan 13, 2023

Conversation

rcomer
Copy link
Member

@rcomer rcomer commented Jan 13, 2023

PR Summary

Fixes #24954 (I think!) I don't claim to fully understand everything that's going on here, but it seems to me that these lines are doing the same job as

# we have already done layout above, so turn it off:
stack.enter_context(self.figure._cm_set(layout_engine='none'))

Since restore_bbox gets called within the above context manager, the final result is the layout engine continues to be what was set with fig.set_layout_engine(None).

PR Checklist

Documentation and Tests

  • Has pytest style unit tests (and pytest passes)
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • [N/A] New plotting related features are documented with examples.

Release Notes

  • [N/A] New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/
  • [N/A] API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/
  • [N/A] Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

@rcomer rcomer force-pushed the adjust_bbox-layout-engine branch from 6e4153c to e93b150 Compare January 13, 2023 14:56
@rcomer rcomer force-pushed the adjust_bbox-layout-engine branch from e93b150 to 3c28528 Compare January 13, 2023 15:12
@@ -532,6 +532,13 @@ def test_savefig_pixel_ratio(backend):
assert ratio1 == ratio2


def test_savefig_preserve_layout_engine(tmp_path):
Copy link
Member

Choose a reason for hiding this comment

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

This worked before didn't it? It was when the rcParam was set that the problem was? Or was the layout still getting set to None, and then falling back to the rcParam?

Otherwise if this works, I'm all for it! I do wish all the context switching were simpler to debug, but...

Copy link
Member Author

Choose a reason for hiding this comment

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

On main this test throws an AttributeError because the layout engine got set to None. If we set the rcParam then we would get an assertion error on main. I'm happy to test either or both.

@tacaswell tacaswell added this to the v3.7.0 milestone Jan 13, 2023
@tacaswell tacaswell merged commit 235b01f into matplotlib:main Jan 13, 2023
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Jan 13, 2023
@jklymak
Copy link
Member

jklymak commented Jan 13, 2023

Thanks for tracking this down @rcomer ! Great detective work....

@rcomer
Copy link
Member Author

rcomer commented Jan 13, 2023

@jklymak thanks to you and @QuLogic for pointing me in the right direction!

oscargus added a commit that referenced this pull request Jan 13, 2023
…971-on-v3.7.x

Backport PR #24971 on branch v3.7.x (FIX: adjust_bbox should not modify layout engine)
@rcomer rcomer deleted the adjust_bbox-layout-engine branch January 16, 2023 17:57
@ksunden ksunden mentioned this pull request Feb 20, 2023
6 tasks
@rcomer rcomer added the PR: bugfix Pull requests that fix identified bugs label Mar 1, 2023
@rcomer rcomer mentioned this pull request Mar 19, 2023
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: bugfix Pull requests that fix identified bugs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: compressed layout setting can be forgotten on second save
3 participants