8000 Merge pull request #21845 from jklymak/fix-bbox-subfigures · matplotlib/matplotlib@9d73164 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9d73164

Browse files
authored
Merge pull request #21845 from jklymak/fix-bbox-subfigures
FIX: bbox subfigures
2 parents 59732ac + 155a2c3 commit 9d73164

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
@@ -1648,18 +1648,21 @@ def get_tightbbox(self, renderer, bbox_extra_artists=None):
16481648
if (np.isfinite(b.width) and np.isfinite(b.height)
16491649
and (b.width != 0 or b.height != 0))]
16501650

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

16581659
_bbox = Bbox.union(bb)
16591660

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

1662-
return bbox_inches
1665+
return _bbox
16631666

16641667
@staticmethod
16651668
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