code: def colorscale(
      cmap,
      values,
      threshold=None,
      symmetric_cmap=True,
      vmax=None,
      vmin=None,
  ):
      """Normalize a cmap, put it in plotly format, get threshold and range."""
      cmap = plt.get_cmap(cmap)
      abs_values = np.abs(values)
      if not symmetric_cmap and (values.min() < 0):
          warnings.warn(
              "you have specified symmetric_cmap=False "
              "but the map contains negative values; "
              "setting symmetric_cmap to True"
          )
          symmetric_cmap = True
      if symmetric_cmap and vmin is not None:
          warnings.warn("vmin cannot be chosen when cmap is symmetric")
          vmin = None
      if vmax is None:
          vmax = abs_values.max()
      # cast to float to avoid TypeError if vmax is a numpy boolean
      vmax = float(vmax)
      if symmetric_cmap:
          vmin = -vmax
      if vmin is None:
          vmin = values.min()
      norm = mpl.colors.Normalize(vmin=vmin, vmax=vmax)
      cmaplist = [cmap(i) for i in range(cmap.N)]
      abs_threshold = None
      if threshold is not None:
          abs_threshold = check_threshold(
              threshold, values, fast_abs_percentile
          )
          istart = int(norm(-abs_threshold, clip=True) * (cmap.N - 1))
          istop = int(norm(abs_threshold, clip=True) * (cmap.N - 1))
          for i in range(istart, istop):
              cmaplist[i] = (
                  0.5,
                  0.5,
                  0.5,
                  1.0,
              )  # just an average gray color
      our_cmap = mpl.colors.LinearSegmentedColormap.from_list(
          "Custom cmap", cmaplist, cmap.N
      )
      x = np.linspace(0, 1, 100)
      rgb = our_cmap(x, bytes=True)[:, :3]
      rgb = np.array(rgb, dtype=int)
      colors = []
      for i, col in zip(x, rgb):
          colors.append(
              [np.round(i, 3), f"rgb({col[0]}, {col[1]}, {col[2]})"]
          )
      return {
          "colors": colors,
          "vmin": vmin,
          "vmax": vmax,
          "cmap": our_cmap,
          "norm": norm,
          "abs_threshold": abs_threshold,
          "symmetric_cmap": symmetric_cmap,
      }
  
file_path: nilearn/nilearn/plotting/js_plotting_utils.py
imports: import base64
  import os
  import warnings
  from string import Template
  import matplotlib
  import matplotlib.pyplot
  import numpy
  from nilearn.plotting.html_document import HTMLDocument, set_max_img_views_before_warning
  from ..None import surface
  from .._utils.extmath import fast_abs_percentile
  from .._utils.param_validation import check_threshold
label_desc: Use image node_id 3 for calling a global function with example usage: colorscale(cmap, values, threshold, symmetric_cmap, vmax, vmin) and returns: dict