code: def default_grid(
      n_items, grid=None, max_cols=4, min_cols=3
  ):  # noqa: D202
      """Make a grid for subplots.
  
      Tries to get as close to sqrt(n_items) x sqrt(n_items) as it can,
      but allows for custom logic
  
      Parameters
      ----------
      n_items : int
          Number of panels required
      grid : tuple
          Number of rows and columns
      max_cols : int
          Maximum number of columns, inclusive
      min_cols : int
          Minimum number of columns, inclusive
  
      Returns
      -------
      (int, int)
          Rows and columns, so that rows * columns >= n_items
      """
  
      if grid is None:
  
          def in_bounds(val):
              return np.clip(val, min_cols, max_cols)
  
          if n_items <= max_cols:
              return 1, n_items
          ideal = in_bounds(round(n_items**0.5))
  
          for offset in (0, 1, -1, 2, -2):
              cols = in_bounds(ideal + offset)
              rows, extra = divmod(n_items, cols)
              if extra == 0:
                  return rows, cols
          return n_items // ideal + 1, ideal
      else:
          rows, cols = grid
          if rows * cols < n_items:
              raise ValueError(
                  "The number of rows times columns is less than the number of subplots"
              )
          if (rows * cols) - n_items >= cols:
              warnings.warn(
                  "The number of rows times columns is larger than necessary"
              )
          return rows, cols
  
imports: import importlib
  import warnings
  from typing import Any, Dict
  import matplotlib
  import numpy
  import packaging
  from matplotlib.colors import to_hex
  from scipy.stats import mode, rankdata
  from scipy.interpolate import CubicSpline
  from ..rcparams import rcParams
  from ..stats.density_utils import kde
  from ..stats import hdi
label_desc: Use image node_id 3 for calling a global function with example usage: default_grid(n_items, grid, max_cols, min_cols) and returns: unknown,  ideal, rows,  cols, np, int,  n_items, rows,  cols