Skip to content

FIX: allow non bbox_extra_artists calls #12635

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 2 commits into from
Oct 28, 2018
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
13 changes: 10 additions & 3 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2296,9 +2296,16 @@ def get_tightbbox(self, renderer, bbox_extra_artists=None):
if bbox is not None and (bbox.width != 0 or bbox.height != 0):
bb.append(bbox)

bb.extend(
ax.get_tightbbox(renderer, bbox_extra_artists=bbox_extra_artists)
for ax in self.axes if ax.get_visible())
for ax in self.axes:
if ax.get_visible():
# some axes don't take the bbox_extra_artists kwarg so we
# need this conditional....
try:
bbox = ax.get_tightbbox(renderer,
bbox_extra_artists=bbox_extra_artists)
except TypeError:
bbox = ax.get_tightbbox(renderer)
bb.append(bbox)

if len(bb) == 0:
return self.bbox_inches
Expand Down
6 changes: 4 additions & 2 deletions lib/mpl_toolkits/axes_grid1/parasite_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,13 @@ def _remove_method(h):

return ax2

def get_tightbbox(self, renderer, call_axes_locator=True):
def get_tightbbox(self, renderer, call_axes_locator=True,
bbox_extra_artists=None):
bbs = [ax.get_tightbbox(renderer, call_axes_locator=call_axes_locator)
for ax in self.parasites]
bbs.append(super().get_tightbbox(renderer,
call_axes_locator=call_axes_locator))
call_axes_locator=call_axes_locator,
bbox_extra_artists=bbox_extra_artists))
return Bbox.union([b for b in bbs if b.width != 0 or b.height != 0])


Expand Down
15 changes: 15 additions & 0 deletions lib/mpl_toolkits/tests/test_axes_grid1.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,3 +406,18 @@ def test_image_grid():
for i in range(4):
grid[i].imshow(im)
grid[i].set_title('test {0}{0}'.format(i))


def test_gettightbbox():
Copy link
Member

Choose a reason for hiding this comment

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

Have you looked at the figure produced in this test? Is it working the way it's supposed to? I get one Axes with one really big Axes overlaid on top of it, but I'm not sure if that's the intended behaviour or not.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, sorry, its not a very good test. But I'm not sure why axes_grid does that, so that's a different issue. The issue here was that the png being made was not being cropped properly to include the big box when bbox_inches='tight' was used.


fig, ax = plt.subplots(figsize=(8, 6))

l, = ax.plot([1, 2, 3], [0, 1, 0])

ax_zoom = zoomed_inset_axes(ax, 4)
ax_zoom.plot([1, 2, 3], [0, 1, 0])

mark_inset(ax, ax_zoom, loc1=1, loc2=3, fc="none", ec='0.3')
bbox = fig.get_tightbbox(fig.canvas.get_renderer())
np.testing.assert_array_almost_equal(bbox.extents,
[-18.022743, -14.118056, 7.332813, 5.4625])