code: def dim_cmap(cmap, factor=0.3, to_white=True):
      """Dim a colormap to white, or to black."""
      assert factor >= 0 and factor <= 1, ValueError(
          "Dimming factor must be larger than 0 and smaller than 1, %s was passed."
          % factor
      )
      if to_white:
          dimmer = lambda c: 1 - factor * (1 - c)
      else:
          dimmer = lambda c: factor * c
      cdict = cmap._segmentdata.copy()
      for c_index, color in enumerate(("red", "green", "blue")):
          color_lst = []
          for value, c1, c2 in cdict[color]:
              color_lst.append((value, dimmer(c1), dimmer(c2)))
          cdict[color] = color_lst
  
      return _colors.LinearSegmentedColormap(
          f"{cmap.name}_dimmed", cdict, _rc["image.lut"]
      )
  
file_path: nipy/nipy/labs/viz_tools/cm.py
imports: import numpy
  from matplotlib import cm
  from matplotlib import colors
  from matplotlib import rcParams
label_desc: Use image node_id 5 for calling a global function with example usage: dim_cmap(cmap, factor, to_white) and returns: _colors