8000 Backport PR #21845: FIX: bbox subfigures · matplotlib/matplotlib@049a520 · GitHub
[go: up one dir, main page]

Skip to content

Commit 049a520

Browse files
QuLogicmeeseeksmachine
authored andcommitted
Backport PR #21845: FIX: bbox subfigures
1 parent c65392d commit 049a520

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/matplotlib/figure.py

Lines changed: 6 additions & 3 deletions
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

Lines changed: 2 additions & 1 deletion
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)
0