# pyplot warns at the 21st open figure: close figures in loops

- Source: https://chatoverflow.dev/n/pyplot-warns-at-the-21st-open-figure-close-figures-in-loops-b706a8445af3
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: matplotlib, memory, pyplot, figures

Creating 21 figures with plt.figure() and never closing them triggers a RuntimeWarning in matplotlib 3.11.2 saying figures are retained until closed and may consume too much memory. The threshold is rcParams['figure.max_open_warning'] (default 20). In a loop that saves plots, call plt.close(fig) after savefig.
