MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / make_layoutgrids

Function make_layoutgrids

lib/matplotlib/_constrained_layout.py:157–199  ·  view source on GitHub ↗

Make the layoutgrid tree. (Sub)Figures get a layoutgrid so we can have figure margins. Gridspecs that are attached to Axes get a layoutgrid so Axes can have margins.

(fig, layoutgrids, rect=(0, 0, 1, 1))

Source from the content-addressed store, hash-verified

155
156
157def make_layoutgrids(fig, layoutgrids, rect=(0, 0, 1, 1)):
158 """
159 Make the layoutgrid tree.
160
161 (Sub)Figures get a layoutgrid so we can have figure margins.
162
163 Gridspecs that are attached to Axes get a layoutgrid so Axes
164 can have margins.
165 """
166
167 if layoutgrids is None:
168 layoutgrids = dict()
169 layoutgrids['hasgrids'] = False
170 if not hasattr(fig, '_parent'):
171 # top figure; pass rect as parent to allow user-specified
172 # margins
173 layoutgrids[fig] = mlayoutgrid.LayoutGrid(parent=rect, name='figlb')
174 else:
175 # subfigure
176 gs = fig._subplotspec.get_gridspec()
177 # it is possible the gridspec containing this subfigure hasn't
178 # been added to the tree yet:
179 layoutgrids = make_layoutgrids_gs(layoutgrids, gs)
180 # add the layoutgrid for the subfigure:
181 parentlb = layoutgrids[gs]
182 layoutgrids[fig] = mlayoutgrid.LayoutGrid(
183 parent=parentlb,
184 name='panellb',
185 parent_inner=True,
186 nrows=1, ncols=1,
187 parent_pos=(fig._subplotspec.rowspan,
188 fig._subplotspec.colspan))
189 # recursively do all subfigures in this figure...
190 for sfig in fig.subfigs:
191 layoutgrids = make_layoutgrids(sfig, layoutgrids)
192
193 # for each Axes at the local level add its gridspec:
194 for ax in fig._localaxes:
195 gs = ax.get_gridspec()
196 if gs is not None:
197 layoutgrids = make_layoutgrids_gs(layoutgrids, gs)
198
199 return layoutgrids
200
201
202def make_layoutgrids_gs(layoutgrids, gs):

Callers 1

do_constrained_layoutFunction · 0.85

Calls 2

make_layoutgrids_gsFunction · 0.85
get_gridspecMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…