code: def colored_line(x, y, c, **kwargs):
      
      # Mask out any NaN values
      nan_mask = ~(np.isnan(x) | np.isnan(y) | np.isnan(c))
      x = x[nan_mask]
      y = y[nan_mask]
      c = c[nan_mask]
  
      # Paste values end to end
      points = concatenate([x, y])
  
      # Exploit numpy's strides to present a view of these points without copying.
      # Dimensions are (segment, start/end, x/y). Since x and y are concatenated back to back,
      # moving between segments only moves one item; moving start to end is only an item;
      # The move between x any moves from one half of the array to the other
      num_pts = points.size // 2
      final_shape = (num_pts - 1, 2, 2)
      final_strides = (points.itemsize, points.itemsize, num_pts * points.itemsize)
      segments = np.lib.stride_tricks.as_strided(points, shape=final_shape,
                                                 strides=final_strides)
  
      # Create a LineCollection from the segments and set it to colormap based on c
      lc = LineCollection(segments, **kwargs)
      lc.set_array(c)
      return lc
docs: Create a multi-colored line.
  
      Takes a set of points and turns them into a collection of lines colored by another array.
  
      Parameters
      ----------
      x : array-like
          x-axis coordinates
      y : array-like
          y-axis coordinates
      c : array-like
          values used for color-mapping
      kwargs : dict
          Other keyword arguments passed to :class:`matplotlib.collections.LineCollection`
  
      Returns
      -------
          The created :class:`matplotlib.collections.LineCollection` instance.