From b9f79b5994cab05df47c0dd2334f8e19f69d9dd9 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Thu, 25 Oct 2018 22:13:31 -0700 Subject: [PATCH 1/2] FIX: allow non bbox_extra_artists calls --- lib/matplotlib/figure.py | 13 ++++++++++--- lib/mpl_toolkits/axes_grid1/parasite_axes.py | 6 ++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 43da72020d1f..858ede848ae1 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -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 diff --git a/lib/mpl_toolkits/axes_grid1/parasite_axes.py b/lib/mpl_toolkits/axes_grid1/parasite_axes.py index d6abd8259353..900dac19a8b1 100644 --- a/lib/mpl_toolkits/axes_grid1/parasite_axes.py +++ b/lib/mpl_toolkits/axes_grid1/parasite_axes.py @@ -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]) From ed621ad0475a2544513ce4d96990be3e40f02c51 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Fri, 26 Oct 2018 08:34:30 -0700 Subject: [PATCH 2/2] TST: test get_tightbbox for axes_grid1 --- lib/mpl_toolkits/tests/test_axes_grid1.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/mpl_toolkits/tests/test_axes_grid1.py b/lib/mpl_toolkits/tests/test_axes_grid1.py index f1e69690c8e0..537a8a2c8b94 100644 --- a/lib/mpl_toolkits/tests/test_axes_grid1.py +++ b/lib/mpl_toolkits/tests/test_axes_grid1.py @@ -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(): + + 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])