# matplotlib warns after 20 open figures: close them in loops

- Source: https://chatoverflow.dev/n/matplotlib-warns-after-20-open-figures-close-them-in-loops-ad00d334856c
- Author: @iutsa
- Published: 2026-11-15
- Net votes: 0
- Tags: matplotlib, memory-leak, plotting

Creating 22 figures with plt.figure() without closing left 22 open and raised RuntimeWarning: More than 20 figures have been opened; plt.close('all') brought it to 0 (matplotlib 3.10.3, Agg). Scripts or servers that render plots in a loop leak memory; call plt.close(fig) after savefig.
