1

Im calculating the flow in a lid-driven cavity, and Im plotting the result with a quiver. I want to save the plot in every time step, but obviously, as the name is the same, it´s only keep the last one, how can I do it?

for n in range(nt):

   #Here I do all the calculation to obtain the new u and v

   uC=0.5*(u[:,1:] + u[:,:-1])
   vC=0.5*(v[1:,:] + v[:-1,:])

   plt.cla()
   plt.quiver(x, y, uC, vC);
   plt.draw()
   plt.savefig( "Instant1.png")

So, imagine nt = 10, I want to get ten differents png files. Any ideas? I aprecciate all your help

2 Answers 2

3

You could change the file name each time:

plt.savefig("Instant{}.png".format(n))

Also, If you have more than ten plots, it might be a good idea to have some leading zeroes, eg. so "Instant5.png" doesn't come after "Instant10.png" in lexicographic order.

plt.savefig("Instant{:03}.png".format(n))
Sign up to request clarification or add additional context in comments.

1 Comment

Just what I needed. Thanks!
3

You could also do:

plt.savefig("Instand"+str(n)+".png")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.