title: matplotlib plot small image without resampling
body: <p>I'm trying to plot a small image in python using matplotlib and would like the displayed axes to have the same shape as the numpy array it was generated from, i.e. the data should not be resampled. In other words, each entry in the array should correspond to a pixel (or thereabouts) on the screen. This seems trivial, but even after trawling the internet for while, I can't seem to get it to work:</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  import matplotlib.cm as cm
  
  X = np.random.rand(30,40)
  
  fig = plt.figure()
  fig.add_axes(aspect="equal",extent=[0, X.shape[1], 0, X.shape[0]])
  ax = fig.gca()
  ax.autoscale_view(True, False, False)
  ax.imshow(X, cmap = cm.gray)
  
  plt.show()
  </code></pre>