I have a code that creates about 50 graphs based on groupby
. The code looks like this:
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)
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.