27

I wrote a script that calls functions from QIIME to build a bunch of plots among other things. Everything runs fine to completion, but matplotlib always throws the following feedback for every plot it creates (super annoying):

/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py:412: 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_num_figures). max_open_warning, RuntimeWarning)

I found this page which seems to explain how to fix this problem , but after I follow directions, nothing changes:

import matplotlib as mpl
mpl.rcParams[figure.max_open_warning'] = 0

I went into the file after calling matplotlib directly from python to see which rcparams file I should be investigating and manually changed the 20 to 0. Still no change. In case the documentation was incorrect, I also changed it to 1000, and still am getting the same warning messages.

I understand that this could be a problem for people running on computers with limited power, but that isn't a problem in my case. How can I make this feedback go away permanently?

gibbone
  • 1,802
  • 17
  • 17
Brassmonkey
  • 381
  • 1
  • 3
  • 4
  • Try this one: http://stackoverflow.com/questions/21884271/warning-about-too-many-open-figures – Aswin Jan 06 '16 at 06:39
  • There is just one opening quote missing before the dictionary key, otherwise this is correct! – smcs Nov 27 '20 at 13:22

3 Answers3

40

Try setting it this way:

import matplotlib as plt
plt.rcParams.update({'figure.max_open_warning': 0})

Not sure exactly why this works, but it mirrors the way I have changed the font size in the past and seems to fix the warnings for me.

Luan Nico
  • 4,966
  • 2
  • 30
  • 56
robb
  • 607
  • 1
  • 6
  • 8
10

Another way I just tried and it worked:

import matplotlib as mpl
mpl.rc('figure', max_open_warning = 0)
ipramusinto
  • 1,960
  • 2
  • 12
  • 24
0

Check out this article: https://heitorpb.github.io/bla/2020/03/18/close-matplotlib-figures/

It basically says to plt.close(fig1) after you're done with fig1. This way you don't have too many figs floating around in memory.