class_docstr: Interface for creating and using matplotlib subplots based on seaborn parameters.
  
  Parameters
  ----------
  subplot_spec : dict
      Keyword args for :meth:`matplotlib.figure.Figure.subplots`.
  facet_spec : dict
      Parameters that control subplot faceting.
  pair_spec : dict
      Parameters that control subplot pairing.
  data : PlotData
      Data used to define figure setup.
class_docstr_tok: ["Interface","for","creating","and","using","matplotlib","subplots","based","on","seaborn","parameters",".","Parameters","--","--","--","--","--","subplot_spec",":","dict","Keyword","args","for",":","meth",":","`","matplotlib.figure.Figure.subplots","`",".","facet_spec",":","dict","Parameters","that","control","subplot","faceting",".","pair_spec",":","dict","Parameters","that","control","subplot","pairing",".","data",":","PlotData","Data","used","to","define","figure","setup","."]
docstr: Initialize matplotlib objects and add seaborn-relevant metadata.
docstr_tok: ["Initialize","matplotlib","objects","and","add","seaborn-relevant","metadata","."]
code: def init_figure(
      self,
      pair_spec: PairSpec,
      pyplot: bool = False,
      figure_kws: dict | None = None,
      target: Axes | Figure | SubFigure | None = None,
  ) -> Figure:
      """Initialize matplotlib objects and add seaborn-relevant metadata."""
      # TODO reduce need to pass pair_spec here?
  
      if figure_kws is None:
          figure_kws = {}
  
      if isinstance(target, mpl.axes.Axes):
          if (
              max(
                  self.subplot_spec["nrows"], self.subplot_spec["ncols"]
              )
              > 1
          ):
              err = " ".join(
                  [
                      "Cannot create multiple subplots after calling `Plot.on` with",
                      f"a {mpl.axes.Axes} object.",
                      f" You may want to use a {mpl.figure.SubFigure} instead.",
                  ]
              )
              raise RuntimeError(err)
  
          self._subplot_list = [
              {
                  "ax": target,
                  "left": True,
                  "right": True,
                  "top": True,
                  "bottom": True,
                  "col": None,
                  "row": None,
                  "x": "x",
                  "y": "y",
              }
          ]
          self._figure = target.figure
          return self._figure
  
      elif isinstance(target, mpl.figure.SubFigure):
          figure = target.figure
      elif isinstance(target, mpl.figure.Figure):
          figure = target
      else:
          if pyplot:
              figure = plt.figure(**figure_kws)
          else:
              figure = mpl.figure.Figure(**figure_kws)
          target = figure
      self._figure = figure
  
      axs = target.subplots(**self.subplot_spec, squeeze=False)
  
      if self.wrap:
          # Remove unused Axes and flatten the rest into a (2D) vector
          axs_flat = axs.ravel({"col": "C", "row": "F"}[self.wrap_dim])
          axs, extra = np.split(axs_flat, [self.n_subplots])
          for ax in extra:
              ax.remove()
          if self.wrap_dim == "col":
              axs = axs[np.newaxis, :]
          else:
              axs = axs[:, np.newaxis]
  
      # Get i, j coordinates for each Axes object
      # Note that i, j are with respect to faceting/pairing,
      # not the subplot grid itself, (which only matters in the case of wrapping).
      iter_axs: np.ndenumerate | zip
      if not pair_spec.get("cross", True):
          indices = np.arange(self.n_subplots)
          iter_axs = zip(zip(indices, indices), axs.flat)
      else:
          iter_axs = np.ndenumerate(axs)
  
      self._subplot_list = []
      for (i, j), ax in iter_axs:
          info = {"ax": ax}
  
          nrows, ncols = (
              self.subplot_spec["nrows"],
              self.subplot_spec["ncols"],
          )
          if not self.wrap:
              info["left"] = j % ncols == 0
              info["right"] = (j + 1) % ncols == 0
              info["top"] = i == 0
              info["bottom"] = i == nrows - 1
          elif self.wrap_dim == "col":
              info["left"] = j % ncols == 0
              info["right"] = ((j + 1) % ncols == 0) or (
                  (j + 1) == self.n_subplots
              )
              info["top"] = j < ncols
              info["bottom"] = j >= (self.n_subplots - ncols)
          elif self.wrap_dim == "row":
              info["left"] = i < nrows
              info["right"] = i >= self.n_subplots - nrows
              info["top"] = i % nrows == 0
              info["bottom"] = ((i + 1) % nrows == 0) or (
                  (i + 1) == self.n_subplots
              )
  
          if not pair_spec.get("cross", True):
              info["top"] = j < ncols
              info["bottom"] = j >= self.n_subplots - ncols
  
          for dim in ["row", "col"]:
              idx = {"row": i, "col": j}[dim]
              info[dim] = self.grid_dimensions[dim][idx]
  
          for axis in "xy":
              idx = {"x": j, "y": i}[axis]
              if axis in pair_spec.get("structure", {}):
                  key = f"{axis}{idx}"
              else:
                  key = axis
              info[axis] = key
  
          self._subplot_list.append(info)
  
      return figure
  
file_path: seaborn/seaborn/_core/subplots.py
imports: from __future__ import annotations
  from collections.abc import Generator
  import numpy
  import matplotlib
  import matplotlib.pyplot
  from matplotlib.axes import Axes
  from matplotlib.figure import Figure
  from typing import TYPE_CHECKING
label_desc: Use image node_id 6 for calling the Subplots obj's underlying member method code with example usage: obj.init_figure(pair_spec, pyplot, figure_kws, target) and returns: figure, self