Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Closing Matplotlib figures [duplicate]

I am using Matplotlib and MPLD3 to create graphs that can be displayed in html plages (using django). Currently my graphs are being generated dynamically from data being pulled from csv files. Every so often I get this message in my Terminal:

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 am not really sure what it means, but I am assuming it means I should have some way of closing graphs that are not in use. Is there anyway to do this or am I completely off base? Thanks.

like image 435
ng150716 Avatar asked Jun 30 '14 22:06

ng150716


People also ask

How do I stop matplotlib from overlapping?

To avoid overlapping of labels and autopct in a matplotlib pie chart, we can follow label as a legend, using legend() method.

Does matplotlib overwrite Savefig?

New! Save questions or answers and organize your favorite content. Learn more.


1 Answers

I preferred the answer of tacaswell in the comments, but had to search for it.

Clean up your plots after you are done with them:

plt.close(fig)

or

plt.close('all')

like image 122
Simon Avatar answered Sep 24 '22 02:09

Simon