简体   繁体   English

如何通过变量名称在matplotlib中保存图形?

[英]How to save a figure in matplotlib by its variable name?

In matplotlib, matplotlib.pyplot.savefig saves the current figure. 在matplotlib中, matplotlib.pyplot.savefig保存当前图形。 If I have multiple figures as variables in my workspace, eg fig1 , fig2 , and fig3 , is it possible to save any of these figures based on their variable name, without first bringing them up as the current figure? 如果我在工作区中有多个图形作为变量,例如fig1fig2fig3 ,是否可以根据它们的变量名称保存其中任何一个,而无需先将它们显示为当前图形? Eg, I'd like to do something like: 例如,我想执行以下操作:

save('fig2', 'fig2_file.png')

You should be able to use Figure.savefig() . 您应该能够使用Figure.savefig() It would look something like this: 它看起来像这样:

fig1.savefig('fig1.png')
fig2.savefig('fig2.png')
fig3.savefig('fig3.png')

You can save individual figures by: 您可以通过以下方式保存单个数字:

figX.savefig('figX_file.png')

.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM