class_docstr: A grid of Axes for Image display.
  
  This class is a specialization of `~.axes_grid1.axes_grid.Grid` for displaying a
  grid of images.  In particular, it forces all axes in a column to share their x-axis
  and all axes in a row to share their y-axis.  It further provides helpers to add
  colorbars to some or all axes.
docstr: Parameters
  ----------
  fig : `.Figure`
      The parent figure.
  rect : (float, float, float, float) or int
      The axes position, as a ``(left, bottom, width, height)`` tuple or
      as a three-digit subplot position code (e.g., "121").
  nrows_ncols : (int, int)
      Number of rows and columns in the grid.
  ngrids : int or None, default: None
      If not None, only the first *ngrids* axes in the grid are created.
  direction : {"row", "column"}, default: "row"
      Whether axes are created in row-major ("row by row") or
      column-major order ("column by column").  This also affects the
      order in which axes are accessed using indexing (``grid[index]``).
  axes_pad : float or (float, float), default: 0.02in
      Padding or (horizontal padding, vertical padding) between axes, in
      inches.
  share_all : bool, default: False
      Whether all axes share their x- and y-axis.  Note that in any case,
      all axes in a column share their x-axis and all axes in a row share
      their y-axis.
  aspect : bool, default: True
      Whether the axes aspect ratio follows the aspect ratio of the data
      limits.
  label_mode : {"L", "1", "all"}, default: "L"
      Determines which axes will get tick labels:
  
      - "L": All axes on the left column get vertical tick labels;
        all axes on the bottom row get horizontal tick labels.
      - "1": Only the bottom left axes is labelled.
      - "all": all axes are labelled.
  
  cbar_mode : {"each", "single", "edge", None}, default: None
      Whether to create a colorbar for "each" axes, a "single" colorbar
      for the entire grid, colorbars only for axes on the "edge"
      determined by *cbar_location*, or no colorbars.  The colorbars are
      stored in the :attr:`cbar_axes` attribute.
  cbar_location : {"left", "right", "bottom", "top"}, default: "right"
  cbar_pad : float, default: None
      Padding between the image axes and the colorbar axes.
  cbar_size : size specification (see `.Size.from_any`), default: "5%"
      Colorbar size.
  cbar_set_cax : bool, default: True
      If True, each axes in the grid has a *cax* attribute that is bound
      to associated *cbar_axes*.
  axes_class : subclass of `matplotlib.axes.Axes`, default: None
docstr_tok: ["Parameters","--","--","--","--","--","fig",":","`",".Figure","`","The","parent","figure",".","rect",":","(","float",",","float",",","float",",","float",")","or","int","The","axes","position",",","as","a","``","(","left",",","bottom",",","width",",","height",")","``","tuple","or","as","a","three-digit","subplot","position","code","(","e.g.",",","``","121","''",")",".","nrows_ncols",":","(","int",",","int",")","Number","of","rows","and","columns","in","the","grid",".","ngrids",":","int","or","None",",","default",":","None","If","not","None",",","only","the","first","*","ngrids","*","axes","in","the","grid","are","created",".","direction",":","{","``","row","''",",","``","column","''","}",",","default",":","``","row","''","Whether","axes","are","created","in","row-major","(","``","row","by","row","''",")","or","column-major","order","(","``","column","by","column","''",")",".","This","also","affects","the","order","in","which","axes","are","accessed","using","indexing","(","``","grid","[","index","]","``",")",".","axes_pad",":","float","or","(","float",",","float",")",",","default",":","0.02in","Padding","or","(","horizontal","padding",",","vertical","padding",")","between","axes",",","in","inches",".","share_all",":","bool",",","default",":","False","Whether","all","axes","share","their","x-","and","y-axis",".","Note","that","in","any","case",",","all","axes","in","a","column","share","their","x-axis","and","all","axes","in","a","row","share","their","y-axis",".","aspect",":","bool",",","default",":","True","Whether","the","axes","aspect","ratio","follows","the","aspect","ratio","of","the","data","limits",".","label_mode",":","{","``","L","''",",","``","1","''",",","``","all","''","}",",","default",":","``","L","''","Determines","which","axes","will","get","tick","labels",":","-","``","L","''",":","All","axes","on","the","left","column","get","vertical","tick","labels",";","all","axes","on","the","bottom","row","get","horizontal","tick","labels",".","-","``","1","''",":","Only","the","bottom","left","axes","is","labelled",".","-","``","all","''",":","all","axes","are","labelled",".","cbar_mode",":","{","``","each","''",",","``","single","''",",","``","edge","''",",","None","}",",","default",":","None","Whether","to","create","a","colorbar","for","``","each","''","axes",",","a","``","single","''","colorbar","for","the","entire","grid",",","colorbars","only","for","axes","on","the","``","edge","''","determined","by","*","cbar_location","*",",","or","no","colorbars",".","The","colorbars","are","stored","in","the",":","attr",":","`","cbar_axes","`","attribute",".","cbar_location",":","{","``","left","''",",","``","right","''",",","``","bottom","''",",","``","top","''","}",",","default",":","``","right","''","cbar_pad",":","float",",","default",":","None","Padding","between","the","image","axes","and","the","colorbar","axes",".","cbar_size",":","size","specification","(","see","`",".Size.from_any","`",")",",","default",":","``","5","%","''","Colorbar","size",".","cbar_set_cax",":","bool",",","default",":","True","If","True",",","each","axes","in","the","grid","has","a","*","cax","*","attribute","that","is","bound","to","associated","*","cbar_axes","*",".","axes_class",":","subclass","of","`","matplotlib.axes.Axes","`",",","default",":","None"]
code: def __init__(
      self,
      fig,
      rect,
      nrows_ncols,
      ngrids=None,
      direction="row",
      axes_pad=0.02,
      *,
      share_all=False,
      aspect=True,
      label_mode="L",
      cbar_mode=None,
      cbar_location="right",
      cbar_pad=None,
      cbar_size="5%",
      cbar_set_cax=True,
      axes_class=None,
  ):
      """
      Parameters
      ----------
      fig : `.Figure`
          The parent figure.
      rect : (float, float, float, float) or int
          The axes position, as a ``(left, bottom, width, height)`` tuple or
          as a three-digit subplot position code (e.g., "121").
      nrows_ncols : (int, int)
          Number of rows and columns in the grid.
      ngrids : int or None, default: None
          If not None, only the first *ngrids* axes in the grid are created.
      direction : {"row", "column"}, default: "row"
          Whether axes are created in row-major ("row by row") or
          column-major order ("column by column").  This also affects the
          order in which axes are accessed using indexing (``grid[index]``).
      axes_pad : float or (float, float), default: 0.02in
          Padding or (horizontal padding, vertical padding) between axes, in
          inches.
      share_all : bool, default: False
          Whether all axes share their x- and y-axis.  Note that in any case,
          all axes in a column share their x-axis and all axes in a row share
          their y-axis.
      aspect : bool, default: True
          Whether the axes aspect ratio follows the aspect ratio of the data
          limits.
      label_mode : {"L", "1", "all"}, default: "L"
          Determines which axes will get tick labels:
  
          - "L": All axes on the left column get vertical tick labels;
            all axes on the bottom row get horizontal tick labels.
          - "1": Only the bottom left axes is labelled.
          - "all": all axes are labelled.
  
      cbar_mode : {"each", "single", "edge", None}, default: None
          Whether to create a colorbar for "each" axes, a "single" colorbar
          for the entire grid, colorbars only for axes on the "edge"
          determined by *cbar_location*, or no colorbars.  The colorbars are
          stored in the :attr:`cbar_axes` attribute.
      cbar_location : {"left", "right", "bottom", "top"}, default: "right"
      cbar_pad : float, default: None
          Padding between the image axes and the colorbar axes.
      cbar_size : size specification (see `.Size.from_any`), default: "5%"
          Colorbar size.
      cbar_set_cax : bool, default: True
          If True, each axes in the grid has a *cax* attribute that is bound
          to associated *cbar_axes*.
      axes_class : subclass of `matplotlib.axes.Axes`, default: None
      """
      _api.check_in_list(
          ["each", "single", "edge", None], cbar_mode=cbar_mode
      )
      _api.check_in_list(
          ["left", "right", "bottom", "top"],
          cbar_location=cbar_location,
      )
      self._colorbar_mode = cbar_mode
      self._colorbar_location = cbar_location
      self._colorbar_pad = cbar_pad
      self._colorbar_size = cbar_size
      # The colorbar axes are created in _init_locators().
  
      super().__init__(
          fig,
          rect,
          nrows_ncols,
          ngrids,
          direction=direction,
          axes_pad=axes_pad,
          share_all=share_all,
          share_x=True,
          share_y=True,
          aspect=aspect,
          label_mode=label_mode,
          axes_class=axes_class,
      )
  
      for ax in self.cbar_axes:
          fig.add_axes(ax)
  
      if cbar_set_cax:
          if self._colorbar_mode == "single":
              for ax in self.axes_all:
                  ax.cax = self.cbar_axes[0]
          elif self._colorbar_mode == "edge":
              for index, ax in enumerate(self.axes_all):
                  col, row = self._get_col_row(index)
                  if self._colorbar_location in ("left", "right"):
                      ax.cax = self.cbar_axes[row]
                  else:
                      ax.cax = self.cbar_axes[col]
          else:
              for ax, cax in zip(self.axes_all, self.cbar_axes):
                  ax.cax = cax
  
imports: from numbers import Number
  import functools
  from types import MethodType
  import numpy
  from matplotlib import _api, cbook
  from matplotlib.gridspec import SubplotSpec
  from .axes_divider import Size, SubplotDivider, Divider
  from .mpl_axes import Axes, SimpleAxisArtist
label_desc: Use image node_id 1 to create a new ImageGrid object from inherited base classes: Grid with example: obj = ImageGrid(fig, rect, nrows_ncols, ngrids, direction, axes_pad)