code: def make_layoutgrids_gs(layoutgrids, gs):
      """
      Make the layoutgrid for a gridspec (and anything nested in the gridspec)
      """
  
      if gs in layoutgrids or gs.figure is None:
          return layoutgrids
      # in order to do constrained_layout there has to be at least *one*
      # gridspec in the tree:
      layoutgrids["hasgrids"] = True
      if not hasattr(gs, "_subplot_spec"):
          # normal gridspec
          parent = layoutgrids[gs.figure]
          layoutgrids[gs] = mlayoutgrid.LayoutGrid(
              parent=parent,
              parent_inner=True,
              name="gridspec",
              ncols=gs._ncols,
              nrows=gs._nrows,
              width_ratios=gs.get_width_ratios(),
              height_ratios=gs.get_height_ratios(),
          )
      else:
          # this is a gridspecfromsubplotspec:
          subplot_spec = gs._subplot_spec
          parentgs = subplot_spec.get_gridspec()
          # if a nested gridspec it is possible the parent is not in there yet:
          if parentgs not in layoutgrids:
              layoutgrids = make_layoutgrids_gs(layoutgrids, parentgs)
          subspeclb = layoutgrids[parentgs]
          # gridspecfromsubplotspec need an outer container:
          # get a unique representation:
          rep = (gs, "top")
          if rep not in layoutgrids:
              layoutgrids[rep] = mlayoutgrid.LayoutGrid(
                  parent=subspeclb,
                  name="top",
                  nrows=1,
                  ncols=1,
                  parent_pos=(
                      subplot_spec.rowspan,
                      subplot_spec.colspan,
                  ),
              )
          layoutgrids[gs] = mlayoutgrid.LayoutGrid(
              parent=layoutgrids[rep],
              name="gridspec",
              nrows=gs._nrows,
              ncols=gs._ncols,
              width_ratios=gs.get_width_ratios(),
              height_ratios=gs.get_height_ratios(),
          )
      return layoutgrids
  
file_path: catboost/contrib/python/matplotlib/py3/matplotlib/_constrained_layout.py
imports: import logging
  import numpy
  from matplotlib import _api, artist
  import matplotlib.transforms
  import matplotlib._layoutgrid
label_desc: Use image node_id 3 for calling a global function with example usage: make_layoutgrids_gs(layoutgrids, gs) and returns: layoutgrids, layoutgrids