MCPcopy
hub / github.com/matplotlib/matplotlib / compress_fixed_aspect

Function compress_fixed_aspect

lib/matplotlib/_constrained_layout.py:268–302  ·  view source on GitHub ↗
(layoutgrids, fig)

Source from the content-addressed store, hash-verified

266
267
268def compress_fixed_aspect(layoutgrids, fig):
269 gs = None
270 for ax in fig.axes:
271 if ax.get_subplotspec() is None:
272 continue
273 ax.apply_aspect()
274 sub = ax.get_subplotspec()
275 _gs = sub.get_gridspec()
276 if gs is None:
277 gs = _gs
278 extraw = np.zeros(gs.ncols)
279 extrah = np.zeros(gs.nrows)
280 elif _gs != gs:
281 raise ValueError('Cannot do compressed layout if Axes are not'
282 'all from the same gridspec')
283 orig = ax.get_position(original=True)
284 actual = ax.get_position(original=False)
285 dw = orig.width - actual.width
286 if dw > 0:
287 extraw[sub.colspan] = np.maximum(extraw[sub.colspan], dw)
288 dh = orig.height - actual.height
289 if dh > 0:
290 extrah[sub.rowspan] = np.maximum(extrah[sub.rowspan], dh)
291
292 if gs is None:
293 raise ValueError('Cannot do compressed layout if no Axes '
294 'are part of a gridspec.')
295 w = np.sum(extraw) / 2
296 layoutgrids[fig].edit_margin_min('left', w)
297 layoutgrids[fig].edit_margin_min('right', w)
298
299 h = np.sum(extrah) / 2
300 layoutgrids[fig].edit_margin_min('top', h)
301 layoutgrids[fig].edit_margin_min('bottom', h)
302 return layoutgrids
303
304
305def get_margin_from_padding(obj, *, w_pad=0, h_pad=0,

Callers 1

do_constrained_layoutFunction · 0.85

Calls 5

edit_margin_minMethod · 0.80
get_subplotspecMethod · 0.45
apply_aspectMethod · 0.45
get_gridspecMethod · 0.45
get_positionMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…