code: def get_tight_layout_figure(
      fig,
      axes_list,
      subplotspec_list,
      renderer,
      pad=1.08,
      h_pad=None,
      w_pad=None,
      rect=None,
  ):
      """
      Return subplot parameters for tight-layouted-figure with specified padding.
  
      Parameters
      ----------
      fig : Figure
      axes_list : list of Axes
      subplotspec_list : list of `.SubplotSpec`
          The subplotspecs of each Axes.
      renderer : renderer
      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.  Defaults to
          *pad*.
      rect : tuple (left, bottom, right, top), default: None.
          rectangle in normalized figure coordinates
          that the whole subplots area (including labels) will fit into.
          Defaults to using the entire figure.
  
      Returns
      -------
      subplotspec or None
          subplotspec kwargs to be passed to `.Figure.subplots_adjust` or
          None if tight_layout could not be accomplished.
      """
  
      # Multiple Axes can share same subplotspec (e.g., if using axes_grid1);
      # we need to group them together.
      ss_to_subplots = {ss: [] for ss in subplotspec_list}
      for ax, ss in zip(axes_list, subplotspec_list):
          ss_to_subplots[ss].append(ax)
      if ss_to_subplots.pop(None, None):
          _api.warn_external(
              "This figure includes Axes that are not compatible with "
              "tight_layout, so results might be incorrect."
          )
      if not ss_to_subplots:
          return {}
      subplot_list = list(ss_to_subplots.values())
      ax_bbox_list = [ss.get_position(fig) for ss in ss_to_subplots]
  
      max_nrows = max(ss.get_gridspec().nrows for ss in ss_to_subplots)
      max_ncols = max(ss.get_gridspec().ncols for ss in ss_to_subplots)
  
      span_pairs = []
      for ss in ss_to_subplots:
          # The intent here is to support Axes from different gridspecs where
          # one's nrows (or ncols) is a multiple of the other (e.g. 2 and 4),
          # but this doesn't actually work because the computed wspace, in
          # relative-axes-height, corresponds to different physical spacings for
          # the 2-row grid and the 4-row grid.  Still, this code is left, mostly
          # for backcompat.
          rows, cols = ss.get_gridspec().get_geometry()
          div_row, mod_row = divmod(max_nrows, rows)
          div_col, mod_col = divmod(max_ncols, cols)
          if mod_row != 0:
              _api.warn_external(
                  "tight_layout not applied: number of rows "
                  "in subplot specifications must be "
                  "multiples of one another."
              )
              return {}
          if mod_col != 0:
              _api.warn_external(
                  "tight_layout not applied: number of "
                  "columns in subplot specifications must be "
                  "multiples of one another."
              )
              return {}
          span_pairs.append(
              (
                  slice(
                      ss.rowspan.start * div_row,
                      ss.rowspan.stop * div_row,
                  ),
                  slice(
                      ss.colspan.start * div_col,
                      ss.colspan.stop * div_col,
                  ),
              )
          )
  
      kwargs = _auto_adjust_subplotpars(
          fig,
          renderer,
          shape=(max_nrows, max_ncols),
          span_pairs=span_pairs,
          subplot_list=subplot_list,
          ax_bbox_list=ax_bbox_list,
          pad=pad,
          h_pad=h_pad,
          w_pad=w_pad,
      )
  
      # kwargs can be none if tight_layout fails...
      if rect is not None and kwargs is not None:
          # if rect is given, the whole subplots area (including
          # labels) will fit into the rect instead of the
          # figure. Note that the rect argument of
          # *auto_adjust_subplotpars* specify the area that will be
          # covered by the total area of axes.bbox. Thus we call
          # auto_adjust_subplotpars twice, where the second run
          # with adjusted rect parameters.
  
          left, bottom, right, top = rect
          if left is not None:
              left += kwargs["left"]
          if bottom is not None:
              bottom += kwargs["bottom"]
          if right is not None:
              right -= 1 - kwargs["right"]
          if top is not None:
              top -= 1 - kwargs["top"]
  
          kwargs = _auto_adjust_subplotpars(
              fig,
              renderer,
              shape=(max_nrows, max_ncols),
              span_pairs=span_pairs,
              subplot_list=subplot_list,
              ax_bbox_list=ax_bbox_list,
              pad=pad,
              h_pad=h_pad,
              w_pad=w_pad,
              rect=(left, bottom, right, top),
          )
  
      return kwargs
  
file_path: matplotlib/lib/matplotlib/_tight_layout.py
imports: import numpy
  import matplotlib
  from matplotlib import _api, artist
  from matplotlib.font_manager import FontProperties
  from matplotlib.transforms import Bbox
label_desc: Use image node_id 3 for calling a global function with example usage: get_tight_layout_figure(fig, axes_list, subplotspec_list, renderer, pad, h_pad, w_pad, rect) and returns: kwargs, dict, dict, dict