1、保存单张图片
import matplotlib.pyplot as pltx=[0,1,2,3,4,5]y=[0,2,4,6,8,10]plt.plot(x,y)plt.savefig( './result/exam_01.png')plt.show()
2、创建文件夹并保存单张图片
import matplotlib.pyplot as pltimport osx=[0,1,2,3,4,5]y=[0,2,4,6,8,10]plt.plot(x,y)figure_save_path = "picture_folder"if not os.path.exists(figure_save_path):os.makedirs(figure_save_path) plt.savefig(os.path.join(figure_save_path , 'exam_02.png'))plt.show()
3、创建文件夹并保存多张图片
import matplotlib.pyplot as pltimport osfor i in range(0,3,1):x=[i,1,2,3,4,5]y=[0,2,4,6,8,10]name_list=["one","two","three"]plt.plot(x,y)figure_save_path = "picture_folder_many"if not os.path.exists(figure_save_path):os.makedirs(figure_save_path) plt.savefig(os.path.join(figure_save_path , name_list[i]))plt.show()