Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3767fd0

Browse files
authored
Merge pull request #19965 from meeseeksmachine/auto-backport-of-pr-19961-on-v3.4.x
Backport PR #19961 on branch v3.4.x (FIX: subfigure tightbbox)
2 parents 5892572 + 07aebc4 commit 3767fd0

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/matplotlib/figure.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1652,7 +1652,11 @@ def get_tightbbox(self, renderer, bbox_extra_artists=None):
16521652
and (b.width != 0 or b.height != 0))]
16531653

16541654
if len(bb) == 0:
1655-
return self.bbox_inches
1655+
if hasattr(self, 'bbox_inches'):
1656+
return self.bbox_inches
1657+
else:
1658+
# subfigures do not have bbox_inches, but do have a bbox
1659+
bb = [self.bbox]
16561660

16571661
_bbox = Bbox.union(bb)
16581662

lib/matplotlib/tests/test_figure.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,15 @@ def test_subfigure():
900900
fig.suptitle('Figure suptitle', fontsize='xx-large')
901901

902902

903+
def test_subfigure_tightbbox():
904+
# test that we can get the tightbbox with a subfigure...
905+
fig = plt.figure(constrained_layout=True)
906+
sub = fig.subfigures(1, 2)
907+
908+
np.testing.assert_allclose(
909+
fig.get_tightbbox(fig.canvas.get_renderer()).width, 0.1)
910+
911+
903912
@image_comparison(['test_subfigure_ss.png'], style='mpl20',
904913
savefig_kwarg={'facecolor': 'teal'},
905914
remove_text=False)

0 commit comments

Comments
 (0)