title: Plot curve with blending line colors with matplotlib/pyplot
body: <p>I want to start the curve with one color and progressively blend into another color until the end. The following function in my MCVE works, but surely, there has to be a better way I haven't found out about, yet?!</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  
  def colorlist(color1, color2, num):
      """Generate list of num colors blending from color1 to color2"""
      result = [np.array(color1), np.array(color2)]
      while len(result) &lt; num:
          temp = [result[0]]
          for i in range(len(result)-1):
              temp.append(np.sqrt((result[i]**2+result[i+1]**2)/2))
              temp.append(result[i+1])
          result = temp
      indices = np.linspace(0, len(result)-1, num).round().astype(int)
      return [result[i] for i in indices]
  
  x = np.linspace(0, 2*np.pi, 100)
  y = np.sin(x)
  colors = colorlist((1, 0, 0), (0, 0, 1), len(x))
  
  for i in range(len(x)-1):
      xi = x[i:i+1+1]
      yi = y[i:i+1+1]
      ci = colors[i]
      plt.plot(xi, yi, color=ci, linestyle='solid', linewidth='10')
  
  plt.show()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/ePfd6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ePfd6.png" alt="1"></a></p>