0

So I was running code earlier and got the following warning:

Warning (from warnings module):
  File "<string>", line 558
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`).

Warning (from warnings module):
  File "<string>", line 665
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`).

Not going to lie, I was being very careless and was still running it anyway, ignoring the warning. Now whenever I try to run the script, my python shell doesn't run the script.

So I am trying to remove the graphs from the memory to allow me to run script again.

I have tried the following and it still won't let me run the code:

  1. plt.clf()
  2. plt.cla()
  3. f = plt.figure() f.clear() plt.close(f)
  4. plt.close('all')
  5. matplotlib.pyplot.figure().clear() matplotlib.pyplot.close()

How can I fix this issue?

William Miller
  • 9,839
  • 3
  • 25
  • 46
fyb123
  • 43
  • 1
  • 5

1 Answers1

0
import matplotlib._pylab_helpers as pylhelp

pylhelp.Gcf().destroy_all()

Though this would work for what you want, this is not a supported interface and might become obsolete. I do not know of any other way of doing this, that is the only reason I recommend it.

XPhyro
  • 419
  • 1
  • 6
  • 16