0

I have a function which has _=plt.plot(dataframe) in it to plot a figure. This function will be called a few times in a loop later and output multiple figure objects.

I wonder how to save the figure objects without knowing their names, as I did not return them. I can see that all figures are printed in my notebook, stacked one by one.

BoX
  • 21
  • 3
  • Well, you aren't saving them in any way. They are probably being garbage collected as soon as the function terminates. If you need data from inside a function, then the most reasonable way to get at it is to have your function *return that data* – juanpa.arrivillaga Nov 25 '20 at 02:39
  • That being said perhaps `matplotlib` keeps track of all these things. – juanpa.arrivillaga Nov 25 '20 at 02:40
  • 1
    See the answer here: https://stackoverflow.com/a/15900439/588071. You can iterate over `plt.get_fignums()`. Something like: `for i in plt.get_fignums(): ; plt.figure(i) ; plt.savefig('figure{:d}.png'.format(i))` – tmdavison Nov 25 '20 at 11:00

0 Answers0