File tree 2 files changed +10
-1
lines changed 2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -287,6 +287,7 @@ the desired format::
287
287
import matplotlib.pyplot as plt
288
288
plt.plot([1, 2, 3])
289
289
plt.savefig('myfig.png')
290
+ plt.close()
290
291
291
292
.. seealso ::
292
293
Original file line number Diff line number Diff line change @@ -1170,7 +1170,7 @@ def disconnect(cid: int) -> None:
1170
1170
1171
1171
def close (fig : None | int | str | Figure | Literal ["all" ] = None ) -> None :
1172
1172
"""
1173
- Close a figure window.
1173
+ Close a figure window, and unregister it from pyplot .
1174
1174
1175
1175
Parameters
1176
1176
----------
@@ -1183,6 +1183,14 @@ def close(fig: None | int | str | Figure | Literal["all"] = None) -> None:
1183
1183
- ``str``: a figure name
1184
1184
- 'all': all figures
1185
1185
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()`.
1186
1194
"""
1187
1195
if fig is None :
1188
1196
manager = _pylab_helpers .Gcf .get_active ()
You can’t perform that action at this time.
0 commit comments