0

In matplotlib.pyplot how do I delete the figure completely?

I have tried plt.close('all') and plt.close(fig) where fig if the figure object returned by plt.figure(), but the interpreter still complains that the figures are opened.

I can't ignore the warning since my script needs to generate hundreds of complex figures.

Rizhiy
  • 775
  • 1
  • 9
  • 31
  • What's the complaint message? – Guimoute Apr 11 '20 at 13:14
  • " RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`)." – Rizhiy Apr 11 '20 at 13:15
  • Ok thanks. Would `fig.close()` help? – Guimoute Apr 11 '20 at 13:28
  • Figure doesn't have `close()` method: https://matplotlib.org/3.2.1/api/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure – Rizhiy Apr 11 '20 at 22:01
  • Oops, I thought it had for the object-oriented variant. Well `plt.close()` works for me in a simple example. Can we take a look at more of your code? Which IDE do you use? It seems like [Eclipse](https://stackoverflow.com/questions/15012309/close-pre-existing-figures-in-matplotlib-when-running-from-eclipse) can cause issues. – Guimoute Apr 12 '20 at 10:12
  • No IDE, I run stuff from the terminal. I already tried `plt.close()` as stated in the question. – Rizhiy Apr 12 '20 at 23:36

0 Answers0