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

FIX: use locators in adjust_bbox#25499

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
oscargus merged 1 commit intomatplotlib:mainfromrcomer:colorbar-bbox_inches
Mar 20, 2023

Conversation

rcomer
Copy link
Member

PR Summary

Fixes#22625. The problem was that_ColorbarAxesLocator was not used to set the aspect ratio beforeadjust_bbox stripped it off. A simpler but presumably less efficient fix might be to trigger a draw before callingadjust_bbox. We already do that ifbbox_inches == "tight".

iflayout_engineisnotNoneorbbox_inches=="tight":
# we need to trigger a draw before printing to make sure
# CL works. "tight" also needs a draw to get the right
# locations:

PR Checklist

Documentation and Tests

  • Has pytest style unit tests (andpytest passes)
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs shouldbuild 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 indoc/users/next_whats_new/
  • [N/A] API changes are marked with a.. versionchanged:: directive in the docstring and documented indoc/api/next_api_changes/
  • [N/A] Release notes conform with instructions innext_whats_new/README.rst ornext_api_changes/README.rst

@rcomerrcomer added this to thev3.7.2 milestoneMar 18, 2023
@rcomerrcomer added the PR: bugfixPull requests that fix identified bugs labelMar 18, 2023
fig, ax = plt.subplots()
pc = ax.pcolormesh(np.random.randn(2, 2))
cbar = fig.colorbar(pc, aspect=40)
fig.savefig(tmp_path / 'foo.png', bbox_inches=mpl.transforms.Bbox([[0, 0], [4, 4]]))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
fig.savefig(tmp_path/'foo.png',bbox_inches=mpl.transforms.Bbox([[0,0], [4,4]]))
fig.savefig(io.BytesIO(),bbox_inches=mpl.transforms.Bbox([[0,0], [4,4]]))

Copy link
MemberAuthor

@rcomerrcomerMar 19, 2023
edited
Loading

Choose a reason for hiding this comment

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

Thanks, I didn't know you could do this but I see it is the convention through this module. So I took the liberty of also updating the test I added at#24971.

greglucas reacted with thumbs up emoji
Copy link
Contributor

Choose a reason for hiding this comment

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

It is likely faster to stay in memory when saving if possible rather than thrashing the hard drive, which I think is why this would be preferred.

rcomer reacted with thumbs up emoji
cbar = fig.colorbar(pc, aspect=40)
fig.savefig(tmp_path / 'foo.png', bbox_inches=mpl.transforms.Bbox([[0, 0], [4, 4]]))

# Check that an aspect ratio has been applied.
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you able to assert against the aspect ratio too?

Copy link
MemberAuthor

@rcomerrcomerMar 19, 2023
edited
Loading

Choose a reason for hiding this comment

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

I couldn't figure out how to check the aspect ratio directly.get_aspect() returns "auto" before and after save.get_box_aspect() returns 40 before and after save. Is there something else I've missed?

Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't know either, I just figured since it was the aspect that was wrong that is better to test against, so figured I would ask if you tried :) but colorbars are never straightforward and there is still an open issue with the get/set aspect on them.#22103

Although here it could also be that the aspect is only changed in the setattr context manager while saving the figure, so you don't get it except while in that context manager?

This still looks good to me!

rcomer reacted with thumbs up emoji
@oscargusoscargus merged commit8ef978d intomatplotlib:mainMar 20, 2023
@lumberbot-app
Copy link

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout v3.7.xgit pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 8ef978d3c3c9461cacb69bb222955c436ad65088
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #25499: FIX: use locators in adjust_bbox'
  1. Push to a named branch:
git push YOURFORK v3.7.x:auto-backport-of-pr-25499-on-v3.7.x
  1. Create a PR against branch v3.7.x, I would have named this PR:

"Backport PR#25499 on branch v3.7.x (FIX: use locators in adjust_bbox)"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove theStill Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free tosuggest an improvement.

@rcomerrcomer deleted the colorbar-bbox_inches branchMarch 20, 2023 21:05
rcomer pushed a commit to rcomer/matplotlib that referenced this pull requestMar 21, 2023
Conflict was caused by the new test being right above the test fromFIX: use locators in adjust_bbox(cherry picked from commit8ef978d)
rcomer pushed a commit to rcomer/matplotlib that referenced this pull requestMar 21, 2023
Conflict was caused by the new test being right above the test frommatplotlib#24816, which is not in the v3.7.x branch.FIX: use locators in adjust_bbox(cherry picked from commit8ef978d)
ksunden added a commit that referenced this pull requestMar 21, 2023
Backport PR#25499: FIX: use locators in adjust_bbox
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@greglucasgreglucasgreglucas approved these changes

Assignees
No one assigned
Labels
PR: bugfixPull requests that fix identified bugs
Projects
None yet
Milestone
v3.7.2
Development

Successfully merging this pull request may close these issues.

[Bug]: Setting bbox_inches to a Bbox in fig.savefig resizes colorbar
3 participants
@rcomer@greglucas@oscargus

[8]ページ先頭

©2009-2025 Movatter.jp