title: How to remove gaps between *images* in matplotlib?
body: <p>Inspired by <a href="https://stackoverflow.com/questions/20057260/how-to-remove-gaps-between-subplots-in-matplotlib">this question</a>, I've been trying to get images plotted without gaps.</p>
  
  <p>In my toy example I have four images that I want to place in two rows. They have different shapes: different number of rows, <em>same number of columns</em>. Despite the differences, they should fit in a single figure without gaps, as in the following illustration:</p>
  
  <p><a href="https://i.stack.imgur.com/dB4dE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dB4dE.png" alt="it fits"></a></p>
  
  <p>When I try to get them together, though, setting <code>plt.subplots_adjust(wspace=0, hspace=0)</code> doesn't do the trick, because the images have different shapes.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>from numpy.random import rand
  import matplotlib.pyplot as plt
  
  test_data = [[rand(10,10), rand(10,10)],[rand(5,10), rand(5,10)]]
  f, axarr = plt.subplots(2,2)
  for i in range(2):
      for j in range(2):
          axarr[i, j].imshow(test_data[i][j])
  plt.tight_layout()
  plt.subplots_adjust(wspace=0, hspace=0)
  plt.show()
  </code></pre>
  
  <p>I've tried playing around with <code>set_aspect</code> and <code>equal</code>, but without luck.</p>
  
  <p><a href="https://i.stack.imgur.com/vHCP9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vHCP9.png" alt="nofits"></a></p>
  
  <p>Does anyone know how to get those gaps away?</p>