vertster123 0 Newbie Poster

I made a program that outputs a large amount of individual data files that I want to create images for. I created a python script that loops through all of the files, but for some odd reason it crashes after doing 17 images. It is always 17 images, and the images are correct. I have no idea what the problem is, I have tried searching for a while, and I figured out that it has something to do with the saving that it doesn't like. I don't know how to fix it though. Here is the code

#!/usr/bin/python

import matplotlib
import matplotlib.pylab as P
from numpy import *
from pylab import meshgrid,cm,imshow,contour,clabel,colorbar,axis,title,show
from matplotlib import pyplot
from optparse import OptionParser

parser = OptionParser()
parser.add_option("-f","--file",dest="filename", help = "read in file name", metavar="FILE")
parser.add_option("-p",dest="points",help = "input # of lattice points")
parser.add_option("-s",dest="slice",help = "input # of slices in data")
(options,args)=parser.parse_args()
line= options.filename
qq= options.points
qqq=options.slice

ny=int(qq)
nz=int(qq)
ns=int(qqq)
sList=arange(0,ns,1)

pre='slice'
it=0
start=70

for k in sList:
    f = open(line,'r')
    list = f.readlines()
    li = [float(elem) for elem in list]
    f.close()

    nyList=arange(0,ny,1)
    nzList=arange(0,nz,1)
    newList=[]

    for i in nyList:
        newList.append([])

    for i in nyList:
        for j in nzList:
            newList[i-1].append(li[(i-1)*nz+j-1])


    save=pre+str(it)
#Something here crashes, don't know what though
    P.figure(it)
    im = imshow(newList,cmap=cm.RdBu)
    colorbar(im) # adding the colorbar on the right
    title('slice')
    P.savefig(save)
    P.close(it)

    it=it+1
    num=str(start+it)
    line='fort.'+ num