title: python saving multiple subplot figures to pdf
body: <p>I am new with python I am trying to save a huge bunch of data into a pdf with figures using PdfPages of matplotlib and subplots. Problem is that I found a blottleneck I dont know how to solve, the code goes something like:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  from matplotlib.backends.backend_pdf import PdfPages
  
  with PdfPages('myfigures.pdf') as pdf:
  for i in range(1000):
      f,axarr = plt.subplots(2, 3)
      plt.subplots(2, 3)
      axarr[0, 0].plot(x1, y1)
      axarr[1, 0].plot(x2, y2)
  
      pdf.savefig(f)
      plt.close('all')
  </code></pre>
  
  <p>Creating a figure each loop it is highly time consuming, but if I put that outside the loop it doesnt clear each plot. Other options I tried like clear() or clf() didnt work either or ended in creating multiple different figures, anyone as an idea on how to put this in a different way so that it goes faster?</p>