title: matplotlib: colorbars and its text labels
body: <p>I'd like to create a <code>colorbar</code> legend for a <code>heatmap</code>, such that the labels are in the center of each discrete color. <a href="https://stackoverflow.com/questions/14406214/moving-x-axis-to-the-top-of-a-plot-in-matplotlib">Example borrowed from here</a>:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  import numpy as np
  from matplotlib.colors import ListedColormap
  
  #discrete color scheme
  cMap = ListedColormap(['white', 'green', 'blue','red'])
  
  #data
  np.random.seed(42)
  data = np.random.rand(4, 4)
  fig, ax = plt.subplots()
  heatmap = ax.pcolor(data, cmap=cMap)
  
  #legend
  cbar = plt.colorbar(heatmap)
  cbar.ax.set_yticklabels(['0','1','2','&gt;3'])
  cbar.set_label('# of contacts', rotation=270)
  
  # put the major ticks at the middle of each cell
  ax.set_xticks(np.arange(data.shape[1]) + 0.5, minor=False)
  ax.set_yticks(np.arange(data.shape[0]) + 0.5, minor=False)
  ax.invert_yaxis()
  
  #labels
  column_labels = list('ABCD')
  row_labels = list('WXYZ')
  ax.set_xticklabels(column_labels, minor=False)
  ax.set_yticklabels(row_labels, minor=False)
  
  plt.show()
  </code></pre>
  
  <p>This generates the following plot:</p>
  
  <p><a href="https://i.stack.imgur.com/v07GA.png" rel="noreferrer"><img src="https://i.stack.imgur.com/v07GA.png" alt="pmesh plot"></a></p>
  
  <p>Ideally I'd like to generate a legend bar which has the four colors and for each color, a label in its center: <code>0,1,2,&gt;3</code>. How can this be achieved?</p>