title: Saving multiple plots
body: <p>i have this code to produce multiple plots from all the text files in a folder. It runs perfectly fine and shows the plots but i cant work out how to then save them all.</p>
  
  <pre><code>import re
  import numpy as np
  import matplotlib.pyplot as plt
  import pylab as pl
  import os
  
  rootdir='C:\documents\Neighbors for each search id'
  
  for subdir,dirs,files in os.walk(rootdir):
   for file in files:
    f=open(os.path.join(subdir,file),'r')
    print file
    data=np.loadtxt(f)
  
    #plot data
    pl.plot(data[:,1], data[:,2], 'gs')
  
    #Put in the errors
    pl.errorbar(data[:,1], data[:,2], data[:,3], data[:,4], fmt='ro')
  
    #Dashed lines showing pmRa=0 and pmDec=0
    pl.axvline(0,linestyle='--', color='k')
    pl.axhline(0,linestyle='--', color='k')
    pl.show()
  
    f.close()
  </code></pre>
  
  <p>I have previously used</p>
  
  <pre><code>fileName="C:\documents\FirstPlot.png"
  plt.savefig(fileName, format="png")
  </code></pre>
  
  <p>but i think this just saves each graph into one file and overwrites the last one. </p>