code: def discretize_cmap(cmap, N):
      """Return a discrete colormap from the continuous colormap cmap.
  
      Parameters
      ----------
      cmap : colormap instance, eg. cm.jet.
      N : Number of colors.
  
      Returns
      -------
      cmap_d : discretized colormap
  
      Example
      -------
      >>> from matplotlib import cm
      >>> djet = discretize_cmap(cm.jet, 5)
      """
  
      cdict = cmap._segmentdata.copy()
      # N colors
      colors_i = np.linspace(0, 1.0, N)
      # N+1 indices
      indices = np.linspace(0, 1.0, N + 1)
      for key in ("red", "green", "blue"):
          # Find the N colors
          D = np.array(cdict[key])
          interp = interpolate.interp1d(D[:, 0], D[:, 1])
          colors = interp(colors_i)
          # Place these colors at the correct indices.
          A = np.zeros((N + 1, 3), float)
          A[:, 0] = indices
          A[1:, 1] = colors
          A[:-1, 2] = colors
          # Create a tuple for the dictionary.
          L = []
          for color in A:
              L.append(tuple(color))
          cdict[key] = tuple(L)
      # Return colormap object.
      return LinearSegmentedColormap("colormap", cdict, 1024)
  
file_path: astroML/astroML/plotting/tools.py
imports: import numpy
  from io import BytesIO
  from matplotlib import pyplot
  from scipy import interpolate
  from matplotlib import image
  from matplotlib.colors import LinearSegmentedColormap
  from matplotlib.transforms import Bbox
  from matplotlib.patches import Ellipse
label_desc: Use image node_id 2 for calling a global function with example usage: discretize_cmap(cmap, N) and returns: LinearSegmentedColormap