Thanks to visit codestin.com
Credit goes to github.com

Skip to content

savefig with bbox_inches='tight' takes account of all text artists (against v1.1.x) #739

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

Merged
merged 3 commits into from
Mar 17, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/matplotlib/axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8267,6 +8267,13 @@ def matshow(self, Z, **kwargs):
integer=True))
return im

def get_default_bbox_extra_artists(self):
Copy link
Member

Choose a reason for hiding this comment

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

Could do with a docstring (and on the figure method).

bbox_extra_artists = [t for t in self.texts if t.get_visible()]
if self.legend_:
bbox_extra_artists.append(self.legend_)
return bbox_extra_artists


def get_tightbbox(self, renderer, call_axes_locator=True):
"""
return the tight bounding box of the axes.
Expand Down
8 changes: 6 additions & 2 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -1984,8 +1984,12 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w',
renderer = self.figure._cachedRenderer
bbox_inches = self.figure.get_tightbbox(renderer)

bb = [a.get_window_extent(renderer) for a \
in kwargs.pop("bbox_extra_artists", [])]
bbox_extra_artists = kwargs.pop("bbox_extra_artists", None)
if bbox_extra_artists is None:
bbox_extra_artists = self.figure.get_default_bbox_extra_artists()

bb = [a.get_window_extent(renderer) for a in bbox_extra_artists]

if bb:
_bbox = Bbox.union([b for b in bb if b.width!=0 or b.height!=0])

Expand Down
7 changes: 7 additions & 0 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,13 @@ def waitforbuttonpress(self, timeout=-1):
return blocking_input(timeout=timeout)


def get_default_bbox_extra_artists(self):
bbox_extra_artists = [t for t in self.texts if t.get_visible()]
for ax in self.axes:
if ax.get_visible():
bbox_extra_artists.extend(ax.get_default_bbox_extra_artists())
return bbox_extra_artists


def get_tightbbox(self, renderer):
"""
Expand Down