title: Matplotlib: How to colorize a large number of line segments as independent gradients, efficiently
body: <p>Python.<em>matplotlib</em>: <strong>How to colorize a large number of line segments as independent gradients, efficiently?</strong><br>
  Already, read <a href="https://stackoverflow.com/questions/8500700/how-to-plot-a-gradient-color-line-in-matplotlib"><strong><em>this</em></strong></a> and <a href="http://matplotlib.org/examples/pylab_examples/multicolored_line.html" rel="nofollow noreferrer"><strong><em>this</em></strong></a> and other stuff; none of them is our answer!  </p>
  
  <p>We have a number of separate lines wish to plot each in gradient color.  </p>
  
  <p>The solution mentioned in first link above, does not work if you have more than one string of line. In other words, changing the color cycle affects everything in the plot not the only line of interest. <em>This is not of our interest at all.</em>   </p>
  
  <p>The second link which is to the matplotlib site uses segmentation of each lines into many. This is not good approach because for a huge number of lines, say, 10000 or even more; even if you choose only 10 segments per line the result is too huge! Even then the resulting lines are not smoothly colored at all! If you make the number of segmentation a function of the line segments for better gradient, the resulting will be really huge! Hard to display, difficult to save as file properly.</p>