Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitba588a5

Browse files
authored
Merge pull request#29848 from meeseeksmachine/auto-backport-of-pr-29839-on-v3.10.x
Backport PR#29839 on branch v3.10.x (Improve docs regarding plt.close().)
2 parents30817f9 +5fde149 commitba588a5

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
@@ -1170,7 +1170,7 @@ def disconnect(cid: int) -> None:
11701170

11711171
defclose(fig:None|int|str|Figure|Literal["all"]=None)->None:
11721172
"""
1173-
Close a figure window.
1173+
Close a figure window, and unregister it from pyplot.
11741174
11751175
Parameters
11761176
----------
@@ -1183,6 +1183,14 @@ def close(fig: None | int | str | Figure | Literal["all"] = None) -> None:
11831183
- ``str``: a figure name
11841184
- 'all': all figures
11851185
1186+
Notes
1187+
-----
1188+
pyplot maintains a reference to figures created with `figure()`. When
1189+
work on the figure is completed, it should be closed, i.e. deregistered
1190+
from pyplot, to free its memory (see also :rc:figure.max_open_warning).
1191+
Closing a figure window created by `show()` automatically deregisters the
1192+
figure. For all other use cases, most prominently `savefig()` without
1193+
`show()`, the figure must be deregistered explicitly using `close()`.
11861194
"""
11871195
iffigisNone:
11881196
manager=_pylab_helpers.Gcf.get_active()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp