code: def get_cmap_safe(cmap):
      """
      Fetch a colormap by name from matplotlib, colorcet, or cmocean.
  
      Parameters
      ----------
      cmap : str or list of str
          Name of the colormap to fetch. If the input is a list of strings,
          it will create a ``ListedColormap`` with the input list.
  
      Returns
      -------
      matplotlib.colors.Colormap
          The requested colormap if available.
  
      Raises
      ------
      ValueError
          If the input colormap name is not valid.
      TypeError
          If the input is a list of items that are not strings.
  
      """
      if isinstance(cmap, str):
          # check if this colormap has been mapped between ipygany
          if cmap in IPYGANY_MAP:
              cmap = IPYGANY_MAP[cmap]
  
          # Try colorcet first
          if has_module("colorcet"):
              import colorcet
  
              try:
                  return colorcet.cm[cmap]
              except KeyError:
                  pass
  
          # Try cmocean second
          if has_module("cmocean"):
              import cmocean
  
              try:
                  return getattr(cmocean.cm, cmap)
              except AttributeError:
                  pass
  
          if not isinstance(cmap, colors.Colormap):
              if inspect.ismodule(colormaps):  # pragma: no cover
                  # Backwards compatibility with matplotlib<3.5.0
                  if not hasattr(colormaps, cmap):
                      raise ValueError(f'Invalid colormap "{cmap}"')
                  cmap = getattr(colormaps, cmap)
              else:
                  try:
                      cmap = colormaps[cmap]
                  except KeyError:
                      raise ValueError(
                          f'Invalid colormap "{cmap}"'
                      ) from None
  
      elif isinstance(cmap, list):
          for item in cmap:
              if not isinstance(item, str):
                  raise TypeError(
                      "When inputting a list as a cmap, each item should be a string."
                  )
  
          cmap = ListedColormap(cmap)
  
      return cmap
  
imports: from __future__ import annotations
  import inspect
  from typing import Optional, Tuple, Union
  from cycler import Cycler, cycler
  from matplotlib.colors import ListedColormap
  import matplotlib.pyplot
  import numpy
  import pyvista
  from pyvista.core.utilities.misc import has_module
  from .None import _vtk
  from ._typing import ColorLike
label_desc: Use image node_id 1 for calling a global function with example usage: get_cmap_safe(cmap) and returns: cmap, colorcet, getattr