Skip to content

Commit be3b9bb

Browse files
authored
Merge pull request #21849 from meeseeksmachine/auto-backport-of-pr-21845-on-v3.5.x
2 parents c65392d + 049a520 commit be3b9bb

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/matplotlib/figure.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1647,18 +1647,21 @@ def get_tightbbox(self, renderer, bbox_extra_artists=None):
16471647
if (np.isfinite(b.width) and np.isfinite(b.height)
16481648
and (b.width != 0 or b.height != 0))]
16491649

1650+
isfigure = hasattr(self, 'bbox_inches')
16501651
if len(bb) == 0:
1651-
if hasattr(self, 'bbox_inches'):
1652+
if isfigure:
16521653
return self.bbox_inches
16531654
else:
16541655
# subfigures do not have bbox_inches, but do have a bbox
16551656
bb = [self.bbox]
16561657

16571658
_bbox = Bbox.union(bb)
16581659

1659-
bbox_inches = TransformedBbox(_bbox, Affine2D().scale(1 / self.dpi))
1660+
if isfigure:
1661+
# transform from pixels to inches...
1662+
_bbox = TransformedBbox(_bbox, self.dpi_scale_trans.inverted())
16601663

1661-
return bbox_inches
1664+
return _bbox
16621665

16631666
@staticmethod
16641667
def _normalize_grid_string(layout):

lib/matplotlib/tests/test_figure.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,8 @@ def test_subfigure_tightbbox():
10301030
sub = fig.subfigures(1, 2)
10311031

10321032
np.testing.assert_allclose(
1033-
fig.get_tightbbox(fig.canvas.get_renderer()).width, 0.1)
1033+
fig.get_tightbbox(fig.canvas.get_renderer()).width,
1034+
8.0)
10341035

10351036

10361037
@image_comparison(['test_subfigure_ss.png'], style='mpl20',

0 commit comments

Comments
 (0)