title: Adding a colorbar whose color corresponds to the different lines in an existing plot
body: <p>My dataset is in the form of : </p>
  
  <pre><code>Data[0] = [headValue,x0,x1,..xN]
  Data[1] = [headValue_ya,ya0,ya1,..yaN] 
  Data[2] = [headValue_yb,yb0,yb1,..ybN]
  ...
  Data[n] = [headvalue_yz,yz0,yz1,..yzN]
  </code></pre>
  
  <p>I want to plot f(y*) =  x, so I can visualize all Lineplots in the same figure with different colors, each color determined by the headervalue_y*. </p>
  
  <p>I also want to add a colorbar whose color matching the lines and therefore the header values, so we can link visually which header value leads to which behaviour.</p>
  
  <p>Here is what I am aiming for :(Plot from Lacroix B, Letort G, Pitayu L, et al. Microtubule Dynamics Scale with Cell Size to Set Spindle Length and Assembly Timing. Dev Cell. 2018;45(4):496–511.e6. doi:10.1016/j.devcel.2018.04.022)</p>
  
  <p><img src="https://i.stack.imgur.com/A96iT.png" alt="plot from Lacroix et al."></p>
  
  <p>I have trouble adding the colorbar, I have tried to extract N colors from a colormap (N is my number of different headValues, or column -1) and then adding for each line plot the color corresponding here is my code to clarify:</p>
  
  <pre><code>import matplotlib as mpl
  import matplotlib.pyplot as plt
  import numpy as np
  
  Data = [['Time',0,0.33,..200],[0.269,4,4.005,...11],[0.362,4,3.999,...16.21],...[0.347,4,3.84,...15.8]]
  headValues = [0.269,0.362,0.335,0.323,0.161,0.338,0.341,0.428,0.245,0.305,0.305,0.314,0.299,0.395,0.32,0.437,0.203,0.41,0.392,0.347]
  # the differents headValues_y* of each column here in a list but also in Data
  # with headValue[0] = Data[1][0], headValue[1] = Data[2][0] ...
  cmap = mpl.cm.get_cmap('rainbow') # I choose my colormap
  rgba = [] # the color container
  for value in headValues:
      rgba.append(cmap(value)) # so rgba will contain a different color for each headValue
  
  fig, (ax,ax1) = plt.subplots(2,1) # creating my figure and two axes to put the Lines and the colorbar
  c = 0 # index for my colors
  for i in range(1, len(Data)):
      ax.plot( Data[0][1:], Data[i][1:] , color = rgba[c])
      # Data[0][1:] is x, Data[i][1:] is y, and the color associated with Data[i][0]
      c +=  1
  
  
  fig.colorbar(mpl.cm.ScalarMappable(cmap= mpl.colors.ListedColormap(rgba)), cax=ax1, orientation='horizontal')   
  # here I create my scalarMappable for my lineplot and with the previously selected colors 'rgba' 
  plt.show()
  </code></pre>
  
  <p>The current result:</p>
  
  <p><img src="https://i.stack.imgur.com/jz0gU.png" alt="Plot Result"></p>
  
  <p>How to add the colorbar on the side or the bottom of the first axis ?</p>
  
  <p>How to properly add a scale to this colorbar correspondig to different headValues ?</p>
  
  <p>How to make the colorbar scale and colors match to the different lines on the plot with the link One color = One headValue ?</p>
  
  <p>I have tried to work with scatterplot which are more convenient to use with scalarMappable but no solution allows me to do all these things at once.</p>