jaib1
jaib1

Reputation: 357

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

In matplotlib, matplotlib.pyplot.savefig saves the current figure. If I have multiple figures as variables in my workspace, e.g. 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? E.g., I'd like to do something like:

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

Upvotes: 0

Views: 304

Answers (2)

Udit Gupta
Udit Gupta

Reputation: 11

You can save individual figures by:

figX.savefig('figX_file.png')

.

Upvotes: 1

Don Kirkby
Don Kirkby

Reputation: 56650

You should be able to use Figure.savefig(). It would look something like this:

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

Upvotes: 1

Related Questions