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" causes huge figures and text far outside figure frame #883

Closed
jordens opened this issue May 21, 2012 · 2 comments
Closed
Assignees

Comments

@jordens
Copy link

jordens commented May 21, 2012

I am unhappy with PR #689 and PR #739. Now with bbox_inches="tight"

import matplotlib.pyplot as plt
plt.text(5, 5, "foo")
plt.savefig("bug1740_text.png", format="png", bbox_inches="tight")

produces a huge mostly empty figure with the frame in the lower left.
It crashes if the text is placed further away from the frame because the figure is becoming too large (ipython issue #1740). I believe the right solution to matplotlib issue #689 would be to only adapt the bbox to the text artists that are decorations of the figure (axes, axes labels, titles) but ignore the text pieces in data coordinate space that fall outside axes frame.

@leejjoon
Copy link
Contributor

Yes. This is an expected side-effect.

First, I just want to clarify that what should be a really buggy behavior is with text outside of axes area with clip_on=True.

plt.text(5, 5, "foo", clip_on=True)

Well, to me, it is about good-enough default behavior. And when I committed change, people (although limited) seemed to like the default behavior.

The heuristics to determine which texts to include in calculating the tight bbox need more improvements and I admit that current implementation is very naive.
On the other hand, a command like suptitle creates a regular text artist and it is not straight-forward to distinguish them from other normal text artists. On the other hand, with annotate command, it is more doable. And I will try to work on that.

For now, I recommend you to explicitly set bbox_extra_artists to prevent the default behavior.

plt.savefig("bug1740_text.png", format="png",
            bbox_inches="tight", bbox_extra_artists=[])

@ghost ghost assigned leejjoon May 22, 2012
@tacaswell
Copy link
Member

I think this should be closed as wont fix, as this is what I would consider the correct behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants