[英]How to save figure with a variable in the same in python plt.savefig() python matplotlib 2020
我见过类似的问题和答案,但它们很旧,不起作用。
for i in range (0,7)
plt.figure()
plt.plot(energia-ef,dos[a-3],linewidth=0.6, color='orange',label='Central')
plt.plot(energia-ef,dos[a-2],linewidth=0.6, color ='orange')
plt.plot(energia-ef,dos[a-1],linewidth=0.6, color ='red',label='Layer')
plt.plot(energia-ef,dos[a],linewidth=0.6, color ='red')
plt.plot((0, 0), (-15, 15), 'k-', linewidth=0.5)
plt.ylabel("DOS (number of states/eV)")
plt.legend()
plt.savefig('/Users/andreaangeletti/Dropbox/data/anand/surface/scan/7/relaxed/dos/p/i.png')
其中 i 应该等于 for 的值。
实际上,我首先必须创建第一组图像,然后我会再次运行代码并重写旧的。
除了 i 变量部分之外,如何使用字符串来指定整个路径名作为 savefig() 参数。
如果你想在不同的时间写它,你需要做;
plt.savefig('/Users/andreaangeletti/Dropbox/data/anand/surface/scan/7/relaxed/dos/p/'+str(i)+'.png',bbox_inches='tight')
然后在for之后,关闭它。
plt.close()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.