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
There is an indentation error in your code. Since your plotting command was not in the loop, it will only create the last plot.
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)