0

I am trying to save images to my computer obtained with savefig. Here is the code :

fig=plt.gcf()
plt.show()
plt.draw()
fig.savefig('filename.jpg')

But I have 200 files. I want to save these images with filename1.jpg, filename2.jpg.....,filename200.jpg. So, each time I want to change the filename. How can I do it?

ali
  • 119
  • 1
  • 3
  • 15

1 Answers1

0

Plot and save in a cycle:

for i in range(200):
   fig=plt.gcf()
   plt.show()
   fig.savefig('filename_{0:03d}.jpg'.format(i))

And you do not need plt.draw after plt.show. And you can save figure without showing.

Serenity
  • 35,289
  • 20
  • 120
  • 115