title: Saving multiple figures to one pdf file in matplotlib
body: <p>I have a code that creates about 50 graphs based on <code>groupby</code>.  The code looks like this:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  from matplotlib.backends.backend_pdf import PdfPages
  
  with PdfPages('foo.pdf') as pdf:
     for i, group in df.groupby('station_id'):
         plt.figure()
  
  
  fig=group.plot(x='year', y='Value',title=str(i)).get_figure()
  pdf.savefig(fig)
  </code></pre>
  
  <p>This is saving only one figure, (the last one in my series) when I would like all of my figures to be stored into one pdf.  Any help would be appreciated.</p>