8000 Merge pull request #12660 from meeseeksmachine/auto-backport-of-pr-12… · matplotlib/matplotlib@0593c59 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0593c59

Browse files
authored
Merge pull request #12660 from meeseeksmachine/auto-backport-of-pr-12635-on-v3.0.x
Backport PR #12635 on branch v3.0.x (FIX: allow non bbox_extra_artists calls)
2 parents e5bde38 + 7c2b45d commit 0593c59

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

lib/matplotlib/figure.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2271,9 +2271,16 @@ def get_tightbbox(self, renderer, bbox_extra_artists=None):
22712271
if bbox is not None and (bbox.width != 0 or bbox.height != 0):
22722272
bb.append(bbox)
22732273

2274-
bb.extend(
2275-
ax.get_tightbbox(renderer, bbox_extra_artists=bbox_extra_artists)
2276-
for ax in self.axes if ax.get_visible())
2274+
for ax in self.axes:
2275+
if ax.get_visible():
2276+
# some axes don't take the bbox_extra_artists kwarg so we
2277+
# need this conditional....
2278+
try:
2279+
bbox = ax.get_tightbbox(renderer,
2280+
bbox_extra_artists=bbox_extra_artists)
2281+
except TypeError:
2282+
bbox = ax.get_tightbbox(renderer)
2283+
bb.append(bbox)
22772284

22782285
if len(bb) == 0:
22792286
return self.bbox_inches

lib/mpl_toolkits/axes_grid1/parasite_axes.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,13 @@ def _remove_method(h):
328328

329329
return ax2
330330

331-
def get_tightbbox(self, renderer, call_axes_locator=True):
331+
def get_tightbbox(self, renderer, call_axes_locator=True,
332+
bbox_extra_artists=None):
332333
bbs = [ax.get_tightbbox(renderer, call_axes_locator=call_axes_locator)
333334
for ax in self.parasites]
334335
bbs.append(super().get_tightbbox(renderer,
335-
call_axes_locator=call_axes_locator))
336+
call_axes_locator=call_axes_locator,
337+
bbox_extra_artists=bbox_extra_artists))
336338
return Bbox.union([b for b in bbs if b.width != 0 or b.height != 0])
337339

338340

lib/mpl_toolkits/tests/test_axes_grid1.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,3 +407,18 @@ def test_image_grid():
407407
for i in range(4):
408408
grid[i].imshow(im)
409409
grid[i].set_title('test {0}{0}'.format(i))
410+
411+
412+
def test_gettightbbox():
413+
414+
fig, ax = plt.subplots(figsize=(8, 6))
415+
416+
l, = ax.plot([1, 2, 3], [0, 1, 0])
417+
418+
ax_zoom = zoomed_inset_axes(ax, 4)
419+
ax_zoom.plot([1, 2, 3], [0, 1, 0])
420+
421+
mark_inset(ax, ax_zoom, loc1=1, loc2=3, fc="none", ec='0.3')
422+
bbox = fig.get_tightbbox(fig.canvas.get_renderer())
423+
np.testing.assert_array_almost_equal(bbox.extents,
424+
[-18.022743, -14.118056, 7.332813, 5.4625])

0 commit comments

Comments
 (0)
0