8000 FIX: allow non bbox_extra_artists calls (#12635) · matplotlib/matplotlib@6af7450 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6af7450

Browse files
jklymaktimhoffm
authored andcommitted
FIX: allow non bbox_extra_artists calls (#12635)
* FIX: allow non bbox_extra_artists calls * TST: test get_tightbbox for axes_grid1
1 parent 13d4bd8 commit 6af7450

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
@@ -2296,9 +2296,16 @@ def get_tightbbox(self, renderer, bbox_extra_artists=None):
22962296
if bbox is not None and (bbox.width != 0 or bbox.height != 0):
22972297
bb.append(bbox)
22982298

2299-
bb.extend(
2300-
ax.get_tightbbox(renderer, bbox_extra_artists=bbox_extra_artists)
2301-
for ax in self.axes if ax.get_visible())
2299+
for ax in self.axes:
2300+
if ax.get_visible():
2301+
# some axes don't take the bbox_extra_artists kwarg so we
2302+
# need this conditional....
2303+
try:
2304+
bbox = ax.get_tightbbox(renderer,
2305+
bbox_extra_artists=bbox_extra_artists)
2306+
except TypeError:
2307+
bbox = ax.get_tightbbox(renderer)
2308+
bb.append(bbox)
23022309

23032310
if len(bb) == 0:
23042311
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
@@ -326,11 +326,13 @@ def _remove_method(h):
326326

327327
return ax2
328328

329-
def get_tightbbox(self, renderer, call_axes_locator=True):
329+
def get_tightbbox(self, renderer, call_axes_locator=True,
330+
bbox_extra_artists=None):
330331
bbs = [ax.get_tightbbox(renderer, call_axes_locator=call_axes_locator)
331332
for ax in self.parasites]
332333
bbs.append(super().get_tightbbox(renderer,
333-
call_axes_locator=call_axes_locator))
334+
call_axes_locator=call_axes_locator,
335+
bbox_extra_artists=bbox_extra_artists))
334336
return Bbox.union([b for b in bbs if b.width != 0 or b.height != 0])
335337

336338

lib/mpl_toolkits/tests/test_axes_grid1.py

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

0 commit comments

Comments
 (0)
0