Error when saving multiple figures to a one multi-page PDF document
<p>I'm trying to save several figures to one multi-page PDF document.  My code is as follows:</p>

<pre><code>import matplotlib.backends.backend_pdf
pdf = matplotlib.backends.backend_pdf.PdfPages('output.pdf')

sns.set_style('darkgrid')

g = sns.factorplot(data=df,
                   x='Date',
                   y='Product_Count',
                   col='Company',
                   col_wrap=4,
                   sharey=False)
g.set_xlabels('')
g.set_ylabels('product count')
g.set_xticklabels(rotation=45)
plt.locator_params(axis = 'x', nbins = 8)

f = sns.factorplot(data=df,
                   x='Date',
                   y='Volume_Count',
                   col='Company',
                   col_wrap=4,
                   sharey=False)
f.set_xlabels('')
f.set_ylabels('volume count')
f.set_xticklabels(rotation=45)
plt.locator_params(axis = 'x', nbins = 8)

figures = [g, f]

for figure in figures:
    pdf.savefig(figure)
pdf.close()
</code></pre>

<p>I'm seeing this error message:  </p>

<pre><code>ValueError: No such figure: &lt;seaborn.axisgrid.FacetGrid object at 0x237CD5F0&gt;
</code></pre>

<p>Is there something wrong with the iteration?</p>

<p><code>g</code> and <code>f</code> are not <a href="http://matplotlib.org/api/figure_api.html#matplotlib.figure.Figure" rel="nofollow"><code>matplotlib.figure.Figure</code></a> objects, they are <a href="https://stanford.edu/~mwaskom/software/seaborn/generated/seaborn.FacetGrid.html" rel="nofollow"><code>seaborn.axisgrid.FacetGrid</code></a> objects (as mentioned by <a href="http://stackoverflow.com/questions/39400135/error-when-saving-multiple-figures-to-a-one-multi-page-pdf-document-python-sea/39408904#comment66127098_39400135">@tcaswell in comments</a>).</p>

<p><code>PdfPages</code> needs the <code>Figure</code> instances, and luckily they are easy to extract from the <code>FacetGrid</code> objects, using <code>g.fig</code> and <code>f.fig</code>.</p>

<p>So, all you need to do is change one line, from </p>

<pre><code>figures = [g, f]
</code></pre>

<p>to:</p>

<pre><code>figures = [g.fig, f.fig]
</code></pre>

python matplotlib seaborn pdfpages