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

Skip to content

Commit 12c96ed

Browse files
committed
FIX: subfigure tightbbox
1 parent a051169 commit 12c96ed

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
@@ -1650,7 +1650,11 @@ def get_tightbbox(self, renderer, bbox_extra_artists=None):
16501650
and (b.width != 0 or b.height != 0))]
16511651

16521652
if len(bb) == 0:
1653-
return self.bbox_inches
1653+
if hasattr(self, 'bbox_inches'):
1654+
return self.bbox_inches
1655+
else:
1656+
# subfigures do not have bbox_inches, but do have a bbox
1657+
bb = [self.bbox]
16541658

16551659
_bbox = Bbox.union(bb)
16561660

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)