| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| 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]])) |
There was a problem hiding this comment.
| 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]])) |
Sorry, something went wrong.
There was a problem hiding this comment.
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.
Sorry, something went wrong.
There was a problem hiding this comment.
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.
Sorry, something went wrong.
| 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. |
There was a problem hiding this comment.
Are you able to assert against the aspect ratio too?
Sorry, something went wrong.
There was a problem hiding this comment.
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?
Sorry, something went wrong.
There was a problem hiding this comment.
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!
Sorry, something went wrong.
|
Owee, I'm MrMeeseeks, Look at me. There seem to be a conflict, please backport manually. Here are approximate instructions:
git checkout v3.7.x git pull
git cherry-pick -x -m1 8ef978d3c3c9461cacb69bb222955c436ad65088
git commit -am 'Backport PR #25499: FIX: use locators in adjust_bbox'
git push YOURFORK v3.7.x:auto-backport-of-pr-25499-on-v3.7.x
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 the Still Needs Manual Backport label once the PR gets merged. If these instructions are inaccurate, feel free to suggest an improvement. |
Sorry, something went wrong.
Conflict was caused by the new test being right above the test from FIX: use locators in adjust_bbox (cherry picked from commit 8ef978d)
Conflict was caused by the new test being right above the test from matplotlib#24816, which is not in the v3.7.x branch. FIX: use locators in adjust_bbox (cherry picked from commit 8ef978d)
Backport PR #25499: FIX: use locators in adjust_bbox
| Back | FazBrowse Home | New Git URL |
PR Summary
Fixes #22625. The problem was that _ColorbarAxesLocator was not used to set the aspect ratio before adjust_bbox stripped it off. A simpler but presumably less efficient fix might be to trigger a draw before calling adjust_bbox. We already do that if bbox_inches == "tight".
matplotlib/lib/matplotlib/backend_bases.py
Lines 2358 to 2361 in 78bf53c
PR Checklist
Documentation and Tests
Release Notes