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

Skip to content

Commit 440a8e0

Browse files
authored
Merge pull request #20023 from anntzer/rtrf
Simplify _redo_transform_rel_fig.
2 parents 5c8cf78 + 87bab66 commit 440a8e0

File tree

1 file changed

+9
-28
lines changed

1 file changed

+9
-28
lines changed

lib/matplotlib/figure.py

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,42 +2011,23 @@ def _redo_transform_rel_fig(self, bbox=None):
20112011
If not None, then the bbox is used for relative bounding box.
20122012
Otherwise it is calculated from the subplotspec.
20132013
"""
2014-
20152014
if bbox is not None:
20162015
self.bbox_relative.p0 = bbox.p0
20172016
self.bbox_relative.p1 = bbox.p1
20182017
return
2019-
2020-
gs = self._subplotspec.get_gridspec()
20212018
# need to figure out *where* this subplotspec is.
2022-
wr = gs.get_width_ratios()
2023-
hr = gs.get_height_ratios()
2024-
nrows, ncols = gs.get_geometry()
2025-
if wr is None:
2026-
wr = np.ones(ncols)
2027-
else:
2028-
wr = np.array(wr)
2029-
if hr is None:
2030-
hr = np.ones(nrows)
2031-
else:
2032-
hr = np.array(hr)
2033-
widthf = np.sum(wr[self._subplotspec.colspan]) / np.sum(wr)
2034-
heightf = np.sum(hr[self._subplotspec.rowspan]) / np.sum(hr)
2035-
2036-
x0 = 0
2037-
if not self._subplotspec.is_first_col():
2038-
x0 += np.sum(wr[:self._subplotspec.colspan.start]) / np.sum(wr)
2039-
2040-
y0 = 0
2041-
if not self._subplotspec.is_last_row():
2042-
y0 += 1 - (np.sum(hr[:self._subplotspec.rowspan.stop]) /
2043-
np.sum(hr))
2044-
2019+
gs = self._subplotspec.get_gridspec()
2020+
wr = np.asarray(gs.get_width_ratios())
2021+
hr = np.asarray(gs.get_height_ratios())
2022+
dx = wr[self._subplotspec.colspan].sum() / wr.sum()
2023+
dy = hr[self._subplotspec.rowspan].sum() / hr.sum()
2024+
x0 = wr[:self._subplotspec.colspan.start].sum() / wr.sum()
2025+
y0 = 1 - hr[:self._subplotspec.rowspan.stop].sum() / hr.sum()
20452026
if self.bbox_relative is None:
2046-
self.bbox_relative = Bbox.from_bounds(x0, y0, widthf, heightf)
2027+
self.bbox_relative = Bbox.from_bounds(x0, y0, dx, dy)
20472028
else:
20482029
self.bbox_relative.p0 = (x0, y0)
2049-
self.bbox_relative.p1 = (x0 + widthf, y0 + heightf)
2030+
self.bbox_relative.p1 = (x0 + dx, y0 + dy)
20502031

20512032
def get_constrained_layout(self):
20522033
"""

0 commit comments

Comments
 (0)