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

Function make_layoutgrids_gs

lib/matplotlib/_constrained_layout.py:202–245  ·  view source on GitHub ↗

Make the layoutgrid for a gridspec (and anything nested in the gridspec)

(layoutgrids, gs)

Source from the content-addressed store, hash-verified

200
201
202def make_layoutgrids_gs(layoutgrids, gs):
203 """
204 Make the layoutgrid for a gridspec (and anything nested in the gridspec)
205 """
206
207 if gs in layoutgrids or gs.figure is None:
208 return layoutgrids
209 # in order to do constrained_layout there has to be at least *one*
210 # gridspec in the tree:
211 layoutgrids['hasgrids'] = True
212 if not hasattr(gs, '_subplot_spec'):
213 # normal gridspec
214 parent = layoutgrids[gs.figure]
215 layoutgrids[gs] = mlayoutgrid.LayoutGrid(
216 parent=parent,
217 parent_inner=True,
218 name='gridspec',
219 ncols=gs._ncols, nrows=gs._nrows,
220 width_ratios=gs.get_width_ratios(),
221 height_ratios=gs.get_height_ratios())
222 else:
223 # this is a gridspecfromsubplotspec:
224 subplot_spec = gs._subplot_spec
225 parentgs = subplot_spec.get_gridspec()
226 # if a nested gridspec it is possible the parent is not in there yet:
227 if parentgs not in layoutgrids:
228 layoutgrids = make_layoutgrids_gs(layoutgrids, parentgs)
229 subspeclb = layoutgrids[parentgs]
230 # gridspecfromsubplotspec need an outer container:
231 # get a unique representation:
232 rep = (gs, 'top')
233 if rep not in layoutgrids:
234 layoutgrids[rep] = mlayoutgrid.LayoutGrid(
235 parent=subspeclb,
236 name='top',
237 nrows=1, ncols=1,
238 parent_pos=(subplot_spec.rowspan, subplot_spec.colspan))
239 layoutgrids[gs] = mlayoutgrid.LayoutGrid(
240 parent=layoutgrids[rep],
241 name='gridspec',
242 nrows=gs._nrows, ncols=gs._ncols,
243 width_ratios=gs.get_width_ratios(),
244 height_ratios=gs.get_height_ratios())
245 return layoutgrids
246
247
248def check_no_collapsed_axes(layoutgrids, fig):

Callers 1

make_layoutgridsFunction · 0.85

Calls 3

get_width_ratiosMethod · 0.80
get_height_ratiosMethod · 0.80
get_gridspecMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…