Error when trying to write a matplotlib plot from Pandas DataFrame to pdf
<p>I'm trying to write a plot from matplotlib to a pdf file but getting an error. </p>

<p>I'm creating a plot using matplotlib from a Pandas DataFrame like this:</p>

<pre><code>bplot = dfbuild.plot(x='Build',kind='barh',stacked='True')
</code></pre>

<p>From the documentation: <a href="http://matplotlib.org/faq/howto_faq.html#save-multiple-plots-to-one-pdf-file" rel="nofollow">http://matplotlib.org/faq/howto_faq.html#save-multiple-plots-to-one-pdf-file</a></p>

<p>It seems like I should be doing it this way:</p>

<pre><code>from matplotlib.backends.backend_pdf import PdfPages
pp = PdfPages(r'c:\temp\page.pdf')
figure = bplot.fig
pp.savefig(figure)
pp.close()
</code></pre>

<p>I get this error: </p>

<pre><code>AttributeError: 'AxesSubplot' object has no attribute 'fig'
</code></pre>

<p>The problem is that <code>dfbuild.plot</code> returns an <code>AxesSubplot</code> and not a <code>Figure</code> instance, which is required by the <code>savefig</code> function.</p>

<p>This solves the issue:</p>

<pre><code>pp.savefig(bplot.figure)
</code></pre>

python pandas matplotlib plot pdfpages