Skip to content

Backport PR #12635 on branch v3.0.x (FIX: allow non bbox_extra_artists calls) #12660

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
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 @@ -2271,9 +2271,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 @@ -328,11 +328,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 @@ -407,3 +407,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():

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])