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

BUG: use tight layout by default when saving matplotlib figures #3635

Closed
wants to merge 3 commits into from

Conversation

neutrinoceros
Copy link
Member

PR Summary

This is a second a second attempt to fix #3601, reusing the patch from #3602
combined with the test framework modifications from #3633 to enable comparisons
for images of different sizes.
Opening as a draft to indicate #3633 takes priority over this.

@cphyc
Copy link
Member

cphyc commented Oct 31, 2021 via email

@neutrinoceros
Copy link
Member Author

I have no experience with this paradigm, so no. What benefits do you expect from this approach ?

@cphyc
Copy link
Member

cphyc commented Nov 1, 2021

I have no experience with this paradigm, so no. What benefits do you expect from this approach ?

According to few sources on matplotlib's issue tracker (see e.g. matplotlib/cheatsheets#30 (comment)), constrained_layout is supposed to be a better version of tight_layout that doesn't screw your layout. To use it, create the figure using

fig = plt.figure(constrained_layout=True)

rather than call fig.tight_layout() _a posteriori`.

@neutrinoceros
Copy link
Member Author

Excellent. I was afraid this would be marginally better and a lot more expensive to implement/maintain, but the cost seems actually equivalent and MPL core devs seem to be unanimous on their preference, so let's try this

@neutrinoceros
Copy link
Member Author

@cphyc turns out this is more than a single line patch, lets see what CI has to say.

@neutrinoceros
Copy link
Member Author

oh and one thing that should be elucidated is how well this two options play together when combined. Users may already be passing box_inches="tight", so if it turns out it's not compatible with constrained_layout=True, it'll be more work to catch that option and warn consumers not to use it.

@neutrinoceros
Copy link
Member Author

So it seems to me that constrained_layout produces smaller diffs... but also doesn't fix the problem I was going at as bbox_inches="tight" does, e.g. here
Screenshot 2021-11-01 at 15 42 24
(the ylabel is fixed by box_inches="tight", while this figure is unchanged using constrained_layout=True)

@cphyc, let me know if you want to have a looks, but otherwise I'll just remove the most recent commit (constrained_layout)

@neutrinoceros
Copy link
Member Author

I realized that my modified testing framework produce nice reports but will upload polluted artifacts that are not suited to update the answer store. This needs more work, but I don't know when I'll be able to manage this, so I'm closing this PR for now.

@neutrinoceros neutrinoceros deleted the hotfix_3601 branch May 19, 2022 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: saving images crops out colorbar labels
2 participants