-3

I am using plt.savefig to save a plot generated by matplotlib.pyplot, and I want to save my figure with different names each time I run the code. How can I do that?

2

1 Answer 1

0

The easiest would probably be to use the current time, if you don't save multiple files per second.

import datetime

ts = datetime.datetime.now().strftime("%Y%m%d-%H.%M.%S")
plt.savefig(f"figure-{ts}.png")
Sign up to request clarification or add additional context in comments.

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.