我想將我的 matplotlib 圖保存到新生成的檔案夾中。我只是沒有得到它來保存我的情節到這條路......
到目前為止,這是我的代碼:
now = datetime.now()
current_time = now.strftime("%m_%d_%Y, %H_%M_%S")
dir_name = "Messdaten " current_time
os.mkdir(dir_name)
my_path = os.path.abspath(os.getcwd())
save_path = my_path "\\" dir_name
path = Path(save_path)
plt.savefig(path)
如果有任何幫助,我將不勝感激!
uj5u.com熱心網友回復:
嘗試使用 os 模塊:
import os
my_path = os.path.abspath(__file__) # Figures out the absolute path
fig.savefig(my_path '/Sub Directory/graph.png')
或者:
script_dir = os.path.dirname(__file__)
results_dir = os.path.join(script_dir, 'Results/')
sample_file_name = "sample"
os.makedirs(results_dir, exist_ok=True)
plt.savefig(os.path.join(results_dir, sample_file_name))
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/415778.html
標籤:
