title: Show a (discrete) colorbar next to a plot as a legend for the (automatically chosen) line colors
body: <p>I tried to make a plot showing many lines, but it is hard to tell them apart. They have different colors, but I would like to make it easy to show which line is which.  A normal legend does not really work so well, since I have more than 10 lines. </p>
  
  <p>The lines follow a logical sequence. I would like to (1) have their color automatically chosen from a colormaps (preferably one that has a smooth ordering, such as viridis or a rainbow).   Then I would like (2) to have the tick marks next to the color bar to correspond to the index <code>i</code> for each line (or better a text label from an array of strings <code>textlabels[i]</code>). </p>
  
  <p>Here's a minimal piece of code (with some gaps where I am not sure what to use). I hope this illustrates what I am trying.  </p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  
  # Genereate some values to plot on the x-axis
  x = np.linspace(0,1,1000)
  
  # Some code to select a (discrete version of) a rainbow/viridis color map
  ...
  
  # Loop over lines that should appear in the plot
  for i in range(0,9):
      # Plot something (using straight lines with different slope as example)
      plt.plot(i*x)
  
  
  # Some code to plot a discrete color bar next 
  # to the plot with ticks showing the value of i   
  ...
  </code></pre>
  
  <p>I currently have this. I would like the color bar to have the ticks with values of <code>i</code>, i.e. 0, 1, 2, ... next to it as tick marks.<br>
  <a href="https://i.stack.imgur.com/E2oxm.png" rel="nofollow noreferrer">Example figure of what I have now.  It is hard to tell the lines apart now.</a></p>