From eea529e60bb618d940105f57f28aec10e2a973bd Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Mon, 31 Mar 2025 13:11:05 +0200 Subject: [PATCH] Improve docs regarding plt.close(). --- doc/users/faq.rst | 1 + lib/matplotlib/pyplot.py | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/doc/users/faq.rst b/doc/users/faq.rst index c86b97033cbd..b08bd75cee4e 100644 --- a/doc/users/faq.rst +++ b/doc/users/faq.rst @@ -287,6 +287,7 @@ the desired format:: import matplotlib.pyplot as plt plt.plot([1, 2, 3]) plt.savefig('myfig.png') + plt.close() .. seealso:: diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 25aa3b558227..44e7e0b7d98a 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -1172,7 +1172,7 @@ def disconnect(cid: int) -> None: def close(fig: None | int | str | Figure | Literal["all"] = None) -> None: """ - Close a figure window. + Close a figure window, and unregister it from pyplot. Parameters ---------- @@ -1185,6 +1185,14 @@ def close(fig: None | int | str | Figure | Literal["all"] = None) -> None: - ``str``: a figure name - 'all': all figures + Notes + ----- + pyplot maintains a reference to figures created with `figure()`. When + work on the figure is completed, it should be closed, i.e. deregistered + from pyplot, to free its memory (see also :rc:figure.max_open_warning). + Closing a figure window created by `show()` automatically deregisters the + figure. For all other use cases, most prominently `savefig()` without + `show()`, the figure must be deregistered explicitly using `close()`. """ if fig is None: manager = _pylab_helpers.Gcf.get_active() pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy