[英]Python - matplotlib autoincrement save figure option
您可以將Figure保存在目錄中。 目錄將以當前日期和數字重命名,並帶有當前時間。 對應代碼:
import os.path
import os, errno
cur_Date = time.strftime("%Y-%m-%d")
cur_Time = time.strftime("%H-%M")
%create directory if it did not exist
try:
os.makedirs(cur_Date)
except OSError as e:
if e.errno != errno.EEXIST:
raise
# your figure creation lines ....
# save the figure to file
fig.savefig(cur_Time+'.png')
因此,托馬斯·庫恩(Thomas Kuhn)的建議有點不客氣-但它的確有效:當您單擊保存框時,它會將圖形保存為標題。 我添加了一個隨機數,這是完整的解決方案:
figure = plt.figure()
figure.canvas.set_window_title("Fig_"+str(np.random.randint(1E8)))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.