code: def layoutcolorbargridspec(
      parents, cax, shrink, aspect, location, pad=0.05
  ):
      """
      Do the layout for a colorbar, to not oeverly pollute colorbar.py
  
      `pad` is in fraction of the original axis size.
      """
  
      gs = parents[0].get_subplotspec().get_gridspec()
      # parent layout box....
      gslb = gs._layoutbox
  
      lb = layoutbox.LayoutBox(
          parent=gslb.parent,
          name=gslb.parent.name + ".cbar",
          artist=cax,
      )
      if location in ("left", "right"):
          lbpos = layoutbox.LayoutBox(
              parent=lb,
              name=lb.name + ".pos",
              tightwidth=False,
              pos=True,
              subplot=False,
              artist=cax,
          )
  
          if location == "right":
              # arrange to right of the gridpec sibbling
              layoutbox.hstack(
                  [gslb, lb],
                  padding=pad * gslb.width,
                  strength="strong",
              )
          else:
              layoutbox.hstack([lb, gslb], padding=pad * gslb.width)
          # constrain the height and center...
          # This isn't quite right.  We'd like the colorbar
          # pos to line up w/ the axes poss, not the size of the
          # gs.
          maxrow = -100000
          minrow = 1000000
          maxax = None
          minax = None
  
          for ax in parents:
              subspec = ax.get_subplotspec()
              nrows, ncols = subspec.get_gridspec().get_geometry()
              for num in [subspec.num1, subspec.num2]:
                  rownum1, colnum1 = divmod(subspec.num1, ncols)
                  if rownum1 > maxrow:
                      maxrow = rownum1
                      maxax = ax
                  if rownum1 < minrow:
                      minrow = rownum1
                      minax = ax
          # invert the order so these are bottom to top:
          maxposlb = minax._poslayoutbox
          minposlb = maxax._poslayoutbox
          # now we want the height of the colorbar pos to be
          # set by the top and bottom of these poss
          # bottom              top
          #     b             t
          # h = (top-bottom)*shrink
          # b = bottom + (top-bottom - h) / 2.
          lbpos.constrain_height(
              (maxposlb.top - minposlb.bottom) * shrink,
              strength="strong",
          )
          lbpos.constrain_bottom(
              (maxposlb.top - minposlb.bottom) * (1 - shrink) / 2
              + minposlb.bottom,
              strength="strong",
          )
  
          # set the width of the pos box
          lbpos.constrain_width(
              lbpos.height * (shrink / aspect), strength="strong"
          )
      elif location in ("bottom", "top"):
          lbpos = layoutbox.LayoutBox(
              parent=lb,
              name=lb.name + ".pos",
              tightheight=True,
              pos=True,
              subplot=False,
              artist=cax,
          )
  
          if location == "bottom":
              layoutbox.vstack([gslb, lb], padding=pad * gslb.width)
          else:
              layoutbox.vstack([lb, gslb], padding=pad * gslb.width)
  
          maxcol = -100000
          mincol = 1000000
          maxax = None
          minax = None
  
          for ax in parents:
              subspec = ax.get_subplotspec()
              nrows, ncols = subspec.get_gridspec().get_geometry()
              for num in [subspec.num1, subspec.num2]:
                  rownum1, colnum1 = divmod(subspec.num1, ncols)
                  if colnum1 > maxcol:
                      maxcol = colnum1
                      maxax = ax
                  if rownum1 < mincol:
                      mincol = colnum1
                      minax = ax
          maxposlb = maxax._poslayoutbox
          minposlb = minax._poslayoutbox
          lbpos.constrain_width(
              (maxposlb.right - minposlb.left) * shrink
          )
          lbpos.constrain_left(
              (maxposlb.right - minposlb.left) * (1 - shrink) / 2
              + minposlb.left
          )
          # set the height of the pos box
          lbpos.constrain_height(
              lbpos.width * shrink * aspect, strength="medium"
          )
  
      return lb, lbpos
  
file_path: catboost/contrib/python/matplotlib/py2/matplotlib/_constrained_layout.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import numpy
  import logging
  import warnings
  from matplotlib.legend import Legend
  import matplotlib.transforms
  import matplotlib._layoutbox
label_desc: Use image node_id 7 for calling a global function with example usage: layoutcolorbargridspec(parents, cax, shrink, aspect, location, pad) and returns: lb,  lbpos