You are doing the right thing to save the plot (just put this code before f.close() and make sure to use pl.savefig and not plt.savefig , since you are importing pyplot as pl ). You just need to give each output chart a different file name.
One way to do this is to add a counter variable that will increment for each file you go through, and add this to the file name, for example, something like this:
fileName = "C:\documents\Plot-%04d.png" % ifile
Another option is to create a unique output file name based on the input file name. You can try something like:
fileName = "C:\documents\Plot-" + "_".join(os.path.split(os.path.join(subdir,file))) + ".png"
This will take the input path and replace any path separators with _ . You can use this as part of your output file name.
illya
source share