title: matplotlib savefig bbox_inches = 'tight' does not ignore invisible axes
body: <p>When you set bbox_inches = 'tight' in Matplotlib's savefig() function, it tries to find the tightest bounding box that encapsulates all the content in your figure window.  Unfortunately, the tightest bounding box appears to include invisible axes.</p>
  
  <p>For example, here is a snippet where setting bbox_inches = 'tight' works as desired:</p>
  
  <pre><code>import matplotlib.pylab as plt
  fig = plt.figure(figsize = (5,5))
  data_ax = fig.add_axes([0.2, 0.2, 0.6, 0.6])
  data_ax.plot([1,2], [1,2])
  plt.savefig('Test1.pdf', bbox_inches = 'tight', pad_inches = 0)
  </code></pre>
  
  <p>which produces:</p>
  
  <p><img src="https://s23.postimg.org/i0d0q0c2j/Test1_page_1.jpg" alt="Nice tight bounding box"></p>
  
  <p>The bounds of the saved pdf correspond to the bounds of the content.  This is great, except that I like to use a set of invisible figure axes to place annotations in.  If the invisible axes extend beyond the bounds of the visible content, then the pdf bounds are larger than the visible content.  For example:</p>
  
  <pre><code>import matplotlib.pylab as plt
  fig = plt.figure(figsize = (5,5))
  fig_ax = fig.add_axes([0, 0, 1, 1], frame_on = False)
  fig_ax.xaxis.set_visible(False)
  fig_ax.yaxis.set_visible(False)
  data_ax = fig.add_axes([0.2, 0.2, 0.6, 0.6])
  data_ax.plot([1,2], [1,2])
  plt.savefig('Test2.pdf', bbox_inches = 'tight', pad_inches = 0)
  </code></pre>
  
  <p>producing</p>
  
  <p><img src="https://s11.postimg.org/sh12wgx1f/Test2_page_1.jpg" alt="Loose bounding box"></p>
  
  <p>How can I force savefig() to ignore invisible items in the figure window?  The only solution I have come up with is to calculate the bounding box myself and explicitly specify the bbox to savefig().</p>
  
  <p>In case it matters, I am running Matplotlib 1.2.1 under Python 2.7.3 on Mac OS X 10.8.5.</p>