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

savefig with bbox_inches='tight' takes account of all text artists #689

Closed
wants to merge 3 commits into from

Conversation

leejjoon
Copy link
Contributor

I have added Figure.get_default_bbox_extra_artists and Axes.get_default_bbox_extra_artists methods. And if bbox_extra_artists is not set for the savefig command, the return value of Figure.get_default_bbox_extra_artists will be used instead.
By default, Figure.get_default_bbox_extra_artists adds all the visible text artists.
I think the default behavior will resolve the issues raised in #688 (although I have not tested this with Basemap).

Note, that the default behavior may result in an incorrect bbox if texts are clipped.
Any feedback will be welcomed.

@@ -8250,6 +8250,11 @@ def matshow(self, Z, **kwargs):
integer=True))
return im

def get_default_bbox_extra_artists(self, renderer):
bbox_extra_artists = [t for t in self.texts if t.get_visible()]
return bbox_extra_artists
Copy link
Member

Choose a reason for hiding this comment

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

Is it really worth creating the extra variable? Why not just write

return [t for t in self.texts if t.get_visible()]

Copy link
Collaborator

Choose a reason for hiding this comment

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

I often like the extra named variable before a return so when I encounter problems down the road I can %debug and get in there and explore more efficiently.

@fperez
Copy link
Member

fperez commented Jan 30, 2012

Thanks! Minor review comments inline, but I can confirm that it fixes the problem both with simple plots and with basemap. Both examples shown in #688 now render correctly.

I imagine this will probably cause test breakages for any images that were rendered with 'tight' (if there were any in the test suite), as their layout will change. But the behavior now looks much better!

@jdh2358
Copy link
Collaborator

jdh2358 commented Feb 26, 2012

I just tested this and it looks good. My only comment is that this looks like a bugfix to me. Would it be too difficult for you @leejjoon to modify the pull request to be against v1.1.x rather than master so it makes it into the upcoming bugfix release?

@leejjoon
Copy link
Contributor Author

leejjoon commented Mar 4, 2012

I opened a new PR #739, which is against v1.1.x. I'm closing this PR.

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

Successfully merging this pull request may close these issues.

None yet

3 participants