title: matplotlib colorbar and histogram with shared axis
body: <p>I would like to display a 2D <code>np.array</code> with <code>imshow</code> and the respective colorbar which should share its axis with a histogram of the <code>np.array</code>. Here is an attempt, however, without shared axes.</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  from matplotlib import cm
  from mpl_toolkits.axes_grid1 import make_axes_locatable
  
  fig, ax = plt.subplots(figsize=(7,10))
  
  data = np.random.normal(0, 0.2, size=(100,100))
  cax = ax.imshow(data, interpolation='nearest', cmap=cm.jet)
  
  divider = make_axes_locatable(plt.gca())
  axBar = divider.append_axes("bottom", '5%', pad='7%')
  axHist = divider.append_axes("bottom", '30%', pad='7%')
  
  cbar = plt.colorbar(cax, cax=axBar, orientation='horizontal')
  axHist.hist(np.ndarray.flatten(data), bins=50)
  
  plt.show()
  </code></pre>
  
  <p>I tried to use the <code>sharex</code> argument in <code>axHist</code> with <code>axHist = divider.append_axes("bottom", '30%', pad='7%', sharex=axBar)</code> but this somehow shifts the histogram data:<a href="https://i.stack.imgur.com/iINwe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iINwe.png" alt="enter image description here"></a></p>
  
  <p>Besides the shared axis x, how could one modify the histogram to take the same colors as the colormap, similar to <a href="https://stackoverflow.com/questions/30608731/how-to-add-colorbar-to-a-histogram">here</a>?</p>