code: def plot_colored_trajectory(points, cmap=None, ax=None, permutation=None,
                              **kwargs):
      
      if not ax:
          fig, ax = pyplot.subplots()
      cmap = get_cmap(cmap)
      xs, ys = project_sequence(points, permutation=permutation)
  
      # We want to color each segment independently...which is annoying.
      segments = []
      for i in range(len(xs) - 1):
          cur_line = []
          x_before = xs[i]
          y_before = ys[i]
          x_after = xs[i+1]
          y_after = ys[i+1]
  
          cur_line.append([x_before, y_before])
          cur_line.append([x_after, y_after])
          segments.append(cur_line)
      segments = np.array(segments)
  
      line_segments = matplotlib.collections.LineCollection(segments, cmap=cmap, **kwargs)
      line_segments.set_array(np.arange(len(segments)))
      ax.add_collection(line_segments)
  
      return ax
docs: Plots trajectories with changing color, simlar to `plot`. Trajectory points
      are tuples (x,y,z) satisfying x + y + z = scale (not checked). The tuples are
      projected and plotted as a curve.
  
      Parameters
      ----------
      points: List of 3-tuples
          The list of tuples to be plotted as a connected curve.
      ax: Matplotlib AxesSubplot, None
          The subplot to draw on.
      cmap: String or matplotlib.colors.Colormap, None
          The name of the Matplotlib colormap to use.
      kwargs:
          Any kwargs to pass through to matplotlib.