Skip to content
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

bbox_inches='tight' implementation.... #19349

Open
jklymak opened this issue Jan 23, 2021 · 0 comments
Open

bbox_inches='tight' implementation.... #19349

jklymak opened this issue Jan 23, 2021 · 0 comments
Milestone

Comments

@jklymak
Copy link
Member

@jklymak jklymak commented Jan 23, 2021

savefig('boo.png', bbox_inches='tight') or savefig('boo.png', bbox_inches=Bbox([[0, 1], [2, 3]])) crops a figure before saving.

The current algorithm basically makes a new canvas that is the new dimensions, applies an extra transform to take into account the crop, and then writes the file to disk. This is problematic, in particular, because our axes are specified in figure-relative units, so changing the size of the figure is a major instability. While it usually works, it did interfere with constrained_layout (#19342, #19339) and fixed-aspect axes. In general, it is a roundabout way to achieve a crop.

It seems instead we should just compose the figure as usual, and then crop just before we save. For raster backends, this is quite trivial - we just crop the image data before the save (pillow even has a crop: https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.crop). The vector backends also seem to have viewports:

Simply adjusting these should be adequate to fulfill bbox_inches requirements without transforming every artist. I imagine this is also substantially faster to draw given the slowness of the transform stack.

ping @anntzer

@jklymak jklymak added this to the v3.5.0 milestone Jan 23, 2021
@QuLogic QuLogic removed this from the v3.5.0 milestone Sep 25, 2021
@QuLogic QuLogic added this to the v3.6.0 milestone Sep 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants