Skip to content

Commit eea529e

Browse files
committed
Improve docs regarding plt.close().
1 parent dc05767 commit eea529e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

doc/users/faq.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ the desired format::
287287
import matplotlib.pyplot as plt
288288
plt.plot([1, 2, 3])
289289
plt.savefig('myfig.png')
290+
plt.close()
290291

291292
.. seealso::
292293

lib/matplotlib/pyplot.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ def disconnect(cid: int) -> None:
11721172

11731173
def close(fig: None | int | str | Figure | Literal["all"] = None) -> None:
11741174
"""
1175-
Close a figure window.
1175+
Close a figure window, and unregister it from pyplot.
11761176
11771177
Parameters
11781178
----------
@@ -1185,6 +1185,14 @@ def close(fig: None | int | str | Figure | Literal["all"] = None) -> None:
11851185
- ``str``: a figure name
11861186
- 'all': all figures
11871187
1188+
Notes
1189+
-----
1190+
pyplot maintains a reference to figures created with `figure()`. When
1191+
work on the figure is completed, it should be closed, i.e. deregistered
1192+
from pyplot, to free its memory (see also :rc:figure.max_open_warning).
1193+
Closing a figure window created by `show()` automatically deregisters the
1194+
figure. For all other use cases, most prominently `savefig()` without
1195+
`show()`, the figure must be deregistered explicitly using `close()`.
11881196
"""
11891197
if fig is None:
11901198
manager = _pylab_helpers.Gcf.get_active()

0 commit comments

Comments
 (0)
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