code: def auto_adjust_subplotpars(
      fig,
      renderer,
      nrows_ncols,
      num1num2_list,
      subplot_list,
      ax_bbox_list=None,
      pad=1.08,
      h_pad=None,
      w_pad=None,
      rect=None,
  ):
      """
      Return a dict of subplot parameters to adjust spacing between subplots.
  
      Note that this function ignores geometry information of subplot
      itself, but uses what is given by the *nrows_ncols* and *num1num2_list*
      parameters.  Also, the results could be incorrect if some subplots have
      ``adjustable=datalim``.
  
      Parameters
      ----------
      nrows_ncols : Tuple[int, int]
          Number of rows and number of columns of the grid.
      num1num2_list : List[int]
          List of numbers specifying the area occupied by the subplot
      subplot_list : list of subplots
          List of subplots that will be used to calculate optimal subplot_params.
      pad : float
          Padding between the figure edge and the edges of subplots, as a
          fraction of the font size.
      h_pad, w_pad : float
          Padding (height/width) between edges of adjacent subplots, as a
          fraction of the font size.  Defaults to *pad*.
      rect : Tuple[float, float, float, float]
          [left, bottom, right, top] in normalized (0, 1) figure coordinates.
      """
      rows, cols = nrows_ncols
  
      font_size_inches = (
          FontProperties(
              size=rcParams["font.size"]
          ).get_size_in_points()
          / 72
      )
      pad_inches = pad * font_size_inches
      if h_pad is not None:
          vpad_inches = h_pad * font_size_inches
      else:
          vpad_inches = pad_inches
  
      if w_pad is not None:
          hpad_inches = w_pad * font_size_inches
      else:
          hpad_inches = pad_inches
  
      if (
          len(num1num2_list) != len(subplot_list)
          or len(subplot_list) == 0
      ):
          raise ValueError
  
      if rect is None:
          margin_left = margin_bottom = margin_right = margin_top = None
      else:
          margin_left, margin_bottom, _right, _top = rect
          if _right:
              margin_right = 1 - _right
          else:
              margin_right = None
          if _top:
              margin_top = 1 - _top
          else:
              margin_top = None
  
      vspaces = [[] for i in range((rows + 1) * cols)]
      hspaces = [[] for i in range(rows * (cols + 1))]
  
      union = Bbox.union
  
      if ax_bbox_list is None:
          ax_bbox_list = []
          for subplots in subplot_list:
              ax_bbox = union(
                  [ax.get_position(original=True) for ax in subplots]
              )
              ax_bbox_list.append(ax_bbox)
  
      for subplots, ax_bbox, (num1, num2) in zip(
          subplot_list, ax_bbox_list, num1num2_list
      ):
          if all([not ax.get_visible() for ax in subplots]):
              continue
  
          tight_bbox_raw = union(
              [
                  ax.get_tightbbox(renderer)
                  for ax in subplots
                  if ax.get_visible()
              ]
          )
          tight_bbox = TransformedBbox(
              tight_bbox_raw, fig.transFigure.inverted()
          )
  
          row1, col1 = divmod(num1, cols)
  
          if num2 is None:
              # left
              hspaces[row1 * (cols + 1) + col1].append(
                  _get_left(tight_bbox, ax_bbox)
              )
              # right
              hspaces[row1 * (cols + 1) + (col1 + 1)].append(
                  _get_right(tight_bbox, ax_bbox)
              )
              # top
              vspaces[row1 * cols + col1].append(
                  _get_top(tight_bbox, ax_bbox)
              )
              # bottom
              vspaces[(row1 + 1) * cols + col1].append(
                  _get_bottom(tight_bbox, ax_bbox)
              )
  
          else:
              row2, col2 = divmod(num2, cols)
  
              for row_i in range(row1, row2 + 1):
                  # left
                  hspaces[row_i * (cols + 1) + col1].append(
                      _get_left(tight_bbox, ax_bbox)
                  )
                  # right
                  hspaces[row_i * (cols + 1) + (col2 + 1)].append(
                      _get_right(tight_bbox, ax_bbox)
                  )
              for col_i in range(col1, col2 + 1):
                  # top
                  vspaces[row1 * cols + col_i].append(
                      _get_top(tight_bbox, ax_bbox)
                  )
                  # bottom
                  vspaces[(row2 + 1) * cols + col_i].append(
                      _get_bottom(tight_bbox, ax_bbox)
                  )
  
      fig_width_inch, fig_height_inch = fig.get_size_inches()
  
      # margins can be negative for axes with aspect applied. And we
      # append + [0] to make minimum margins 0
  
      if not margin_left:
          margin_left = max(
              [sum(s) for s in hspaces[:: cols + 1]] + [0]
          )
          margin_left += pad_inches / fig_width_inch
  
      if not margin_right:
          margin_right = max(
              [sum(s) for s in hspaces[cols :: cols + 1]] + [0]
          )
          margin_right += pad_inches / fig_width_inch
  
      if not margin_top:
          margin_top = max([sum(s) for s in vspaces[:cols]] + [0])
          margin_top += pad_inches / fig_height_inch
  
      if not margin_bottom:
          margin_bottom = max([sum(s) for s in vspaces[-cols:]] + [0])
          margin_bottom += pad_inches / fig_height_inch
  
      if margin_left + margin_right >= 1:
          margin_left = 0.4999
          margin_right = 0.4999
          warnings.warn(
              "The left and right margins cannot be made large "
              "enough to accommodate all axes decorations. "
          )
      if margin_bottom + margin_top >= 1:
          margin_bottom = 0.4999
          margin_top = 0.4999
          warnings.warn(
              "The bottom and top margins cannot be made large "
              "enough to accommodate all axes decorations. "
          )
  
      kwargs = dict(
          left=margin_left,
          right=1 - margin_right,
          bottom=margin_bottom,
          top=1 - margin_top,
      )
      if cols > 1:
          hspace = (
              max(
                  sum(s)
                  for i in range(rows)
                  for s in hspaces[
                      i * (cols + 1) + 1 : (i + 1) * (cols + 1) - 1
                  ]
              )
              + hpad_inches / fig_width_inch
          )
          # axes widths:
          h_axes = (
              1 - margin_right - margin_left - hspace * (cols - 1)
          ) / cols
          if h_axes < 0:
              warnings.warn(
                  "tight_layout cannot make axes width small enough "
                  "to accommodate all axes decorations"
              )
              kwargs["wspace"] = 0.5
          else:
              kwargs["wspace"] = hspace / h_axes
  
      if rows > 1:
          vspace = (
              max(sum(s) for s in vspaces[cols:-cols])
              + vpad_inches / fig_height_inch
          )
          v_axes = (
              1 - margin_top - margin_bottom - vspace * (rows - 1)
          ) / rows
          if v_axes < 0:
              warnings.warn(
                  "tight_layout cannot make axes height small enough "
                  "to accommodate all axes decorations"
              )
              kwargs["hspace"] = 0.5
          else:
              kwargs["hspace"] = vspace / v_axes
  
      return kwargs
  
file_path: catboost/contrib/python/matplotlib/py2/matplotlib/tight_layout.py
imports: import warnings
  import matplotlib
  from matplotlib.transforms import TransformedBbox, Bbox
  from matplotlib.font_manager import FontProperties
label_desc: Use image node_id 5 for calling a global function with example usage: auto_adjust_subplotpars(fig, renderer, nrows_ncols, num1num2_list, subplot_list, ax_bbox_list, pad, h_pad, w_pad, rect) and returns: kwargs