MCPcopy
hub / github.com/matplotlib/matplotlib / get_margin_from_padding

Function get_margin_from_padding

lib/matplotlib/_constrained_layout.py:305–340  ·  view source on GitHub ↗
(obj, *, w_pad=0, h_pad=0,
                            hspace=0, wspace=0)

Source from the content-addressed store, hash-verified

303
304
305def get_margin_from_padding(obj, *, w_pad=0, h_pad=0,
306 hspace=0, wspace=0):
307
308 ss = obj._subplotspec
309 gs = ss.get_gridspec()
310
311 if hasattr(gs, 'hspace'):
312 _hspace = (gs.hspace if gs.hspace is not None else hspace)
313 _wspace = (gs.wspace if gs.wspace is not None else wspace)
314 else:
315 _hspace = (gs._hspace if gs._hspace is not None else hspace)
316 _wspace = (gs._wspace if gs._wspace is not None else wspace)
317
318 _wspace = _wspace / 2
319 _hspace = _hspace / 2
320
321 nrows, ncols = gs.get_geometry()
322 # there are two margins for each direction. The "cb"
323 # margins are for pads and colorbars, the non-"cb" are
324 # for the Axes decorations (labels etc).
325 margin = {'leftcb': w_pad, 'rightcb': w_pad,
326 'bottomcb': h_pad, 'topcb': h_pad,
327 'left': 0, 'right': 0,
328 'top': 0, 'bottom': 0}
329 if _wspace / ncols > w_pad:
330 if ss.colspan.start > 0:
331 margin['leftcb'] = _wspace / ncols
332 if ss.colspan.stop < ncols:
333 margin['rightcb'] = _wspace / ncols
334 if _hspace / nrows > h_pad:
335 if ss.rowspan.stop < nrows:
336 margin['bottomcb'] = _hspace / nrows
337 if ss.rowspan.start > 0:
338 margin['topcb'] = _hspace / nrows
339
340 return margin
341
342
343def make_layout_margins(layoutgrids, fig, renderer, *, w_pad=0, h_pad=0,

Callers 1

make_layout_marginsFunction · 0.85

Calls 2

get_gridspecMethod · 0.45
get_geometryMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…