title: Adjusting space around figure with subplots
body: <p>I'm using Matplotlib and struggling to get exactly the right amount of whitespace around a figure I'm plotting that contains a grid of subplots.</p>
  
  <p>Requirements:  be able to choose the aspect ratio of all the subplots (they're all the same), define exactly how much whitespace there is between the subplots and the top, bottom and left of the (saved) figure edge.  I don't need any extra space on the right.</p>
  
  <p>The code I have so far contains the following:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  fig, axes = plt.subplots(ncols=6, nrows=2, sharex=True, 
                           sharey=True, figsize=(16,8))
  
  axes[0,0].plot(x,y)
  etc...
  
  plt.subplots_adjust(hspace=1.0, wspace=0.02, bottom=0.17, left=0.075, top=0.18)
  
  plt.savefig('Fig1_matplot.pdf', bbox_inches='tight')
  </code></pre>
  
  <p>As it is, if I don't specify <code>figsize=()</code> the aspect ratio of the subplots is wrong.  If I do, then the aspect ratio changes whenever I change parameters in <code>subplots_adjust()</code>.  Apparently <code>left cannot be &gt;= right</code> and <code>bottom cannot be &gt;= top</code>.  If I do define top to be anything other than 0 it completely compresses all of the subplots down to a line at the bottom of the figure.  </p>
  
  <p>If I specify <code>bbox_inches='tight'</code> then it cuts off my defined whitespace at the bottom and left, but if I don't specify it then I'm left with excess whitespace on the right since I can't get rid of it (right would be &lt;= left).</p>
  
  <p>I'm a bit stuck, any help would be much appreciated.</p>
  
  <p>Cheers. </p>