title: make multiple plots per page and over several pages inside a 'for' loop for matplotlib in python
body: <p>I need to generate over 100 plots (line diagrams) from a numerical model. The code so far is generating plots specified inside the loop, but it keeps adding multiple lines to the same 4 plots. I want it to finish making 4 plots, then open a new page and draw those 4 plots again and again, so I should have say 25 pages with 100 plots in total.</p>
  
  <p>The code so far - I am starting small and want to generate 12 plots over 3 pages and save it as a file 'plot.pdf' :</p>
  
  <pre><code>from t2listing import *
  import matplotlib.pylot as plt
  from matplotlib.backends.backend_pdf import PdfPages
  
  lst = t2listing('WAI1515PR_AW_407_ayfixold2.listing')
  
  pdf_pages = PdfPages('plot.pdf')
  
  feed = lst.generation.row_name
  
  zone = feed[0:12]
  
  sub = [221, 222, 223, 224]
  
  for i in xrange(3):
      fig = plt.figure()
      for zone,sub in in zip(feed[0:12],(10/4+1)*sub):
          (time, massflow) = lst.history([('g',zone,'Generation rate')])
          ax1 = fig.add_subplot(sub)
          ax1.plot(time, massflow, 'k-')
          plt.ylabel('massflow kg/s')
          plt.xlabel('time in seconds')
          plt.title('GENER data')
          plt.tight_layout()
          plt.savefig('plot.pdf')
      pdf_pages.savefig(fig)
      pdf_pages.close()
  </code></pre>
  
  <p>The result so far is that I get 4 plots, each with 3 line diagrams on it, any possible way to get 12 separate plots?</p>