title: Custom Colorbar-like plot with matplotlib
body: <p>I'm looking to make a colorbar like plot, like so:</p>
  
  <p><img src="https://i.stack.imgur.com/FMCb8.png" alt=""></p>
  
  <p>but with a controllable color, for example I have the following x and y arrays:</p>
  
  <pre><code>x = [0,1,2,4,7,8]
  y = [1,2,1,3,4,5]
  </code></pre>
  
  <p>Then I would have a colorbar like the above picture, but when y=1, it would color red, y=2: green, y=3: blue, y=4:black, etc.</p>
  
  <p>Here is the python code that I modified from matplotlib's gallery:</p>
  
  <pre><code>from matplotlib import pyplot
  import matplotlib as mpl
  
  fig = pyplot.figure(figsize=(8,1))
  ax2 = fig.add_axes([0.05, 0.25, 0.9, 0.5])
  
  cmap = mpl.cm.Accent
  norm = mpl.colors.Normalize(vmin=5, vmax=10)
  bounds = [1, 2, 4, 7, 8]
  norm = mpl.colors.BoundaryNorm(bounds, cmap.N)
  cb2 = mpl.colorbar.ColorbarBase(ax2, cmap=cmap,
                                   norm=norm,
                                   boundaries=[0]+bounds+[13],
                                   ticks=bounds, # optional
                                   spacing='proportional',
                                   orientation='horizontal')
  </code></pre>