class_docstr: A base class of GridSpec that specifies the geometry of the grid
  that a subplot will be placed.
class_docstr_tok: ["A","base","class","of","GridSpec","that","specifies","the","geometry","of","the","grid","that","a","subplot","will","be","placed","."]
docstr: Check if the figure already has a gridspec with these dimensions,
  or create a new one
code: def _check_gridspec_exists(figure, nrows, ncols):
      """
      Check if the figure already has a gridspec with these dimensions,
      or create a new one
      """
      for ax in figure.get_axes():
          gs = ax.get_gridspec()
          if gs is not None:
              if hasattr(gs, "get_topmost_subplotspec"):
                  # This is needed for colorbar gridspec layouts.
                  # This is probably OK because this whole logic tree
                  # is for when the user is doing simple things with the
                  # add_subplot command.  For complicated layouts
                  # like subgridspecs the proper gridspec is passed in...
                  gs = gs.get_topmost_subplotspec().get_gridspec()
              if gs.get_geometry() == (nrows, ncols):
                  return gs
      # else gridspec not found:
      return GridSpec(nrows, ncols, figure=figure)
  
imports: import copy
  import logging
  from numbers import Integral
  import numpy
  import matplotlib
  from matplotlib import _api, _pylab_helpers, _tight_layout
  from matplotlib.transforms import Bbox
label_desc: Use image node_id 11 for calling the GridSpecBase obj's underlying member method code with example usage: obj._check_gridspec_exists(figure, nrows, ncols) and returns: GridSpec, gs