title: How to speed up matplotlib when plotting and saving lots of figures?
body: <p>I am processing observing data from many antenna baseline. Currently what I am working is to plot ~ 40 figures, each of which has 4x5 subplot region. I found it slow when plotting and saving figures with matplotlib in loops. Here are my codes:</p>
  
  <pre><code>    import numpy as np
      import matplotlib.pyplot as plt
      import time
      ...
  
      PLT_PAGE_NUM = 39 # default is 39
      SUB_PLT_NUM = 20 # default is 20
  
      for pp in xrange(0,PLT_PAGE_NUM):
  
          plt.figure(figsize=(20,12))
  
          start_time = time.clock() 
          for kk in xrange(0,SUB_PLT_NUM):
              plt.subplot(5,4,kk+1)
              plt.plot(np.arange(0,TIME_LENGTH), xcor_real_arr[20*pp+kk,0:],'r-',
                       range(0,TIME_LENGTH), xcor_imag_arr[20*pp+kk,0:],'b-')
              plt.title('XCOR of '+ ind_arr[20*pp+kk], color='k') 
  
          plt.savefig('test_imag_real'+str(pp)+'.png',format='png',dpi=100)
          print 'Fig-'+str(pp)+' has been saved'
          print "Excution time:", time.clock()-start_time
  </code></pre>
  
  <p>And the excution time info is:</p>
  
  <pre><code>######### Check your inputs setting #########
  You have selected 2 files.
  The time interval is From 2011-10-20_14:28:38 to 2011-10-20_15:10:54
  Your time resolution is set to 1.125s
  The total plot points number is: 100
  Your frequency channel is: ch2
  ######### Hardworking...please wait #########
  Fig-0 has been saved
  Excution time: *2.52576639619*
  Fig-1 has been saved
  Excution time: *2.59867230708*
  Fig-2 has been saved
  Excution time: *2.81915188482*
  Fig-3 has been saved
  Excution time: *2.83102198991*
  Program ends
  </code></pre>
  
  <p>As you have seen, I just plot 4 figures which cost about 11 seconds. It takes ~2 minutes to plot and save all 39 figures. I dont' know where the bottleneck is. May you help to make it faster? 
  <strong>Thanks!</strong> </p>