MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / close

Function close

lib/matplotlib/pyplot.py:1268–1313  ·  view source on GitHub ↗

Close a figure window, and unregister it from pyplot. Parameters ---------- fig : None or int or str or `.Figure` The figure to close. There are a number of ways to specify this: - *None*: the current figure - `.Figure`: the given `.Figure` instance

(fig: None | int | str | Figure | Literal["all"] = None)

Source from the content-addressed store, hash-verified

1266
1267
1268def close(fig: None | int | str | Figure | Literal["all"] = None) -> None:
1269 """
1270 Close a figure window, and unregister it from pyplot.
1271
1272 Parameters
1273 ----------
1274 fig : None or int or str or `.Figure`
1275 The figure to close. There are a number of ways to specify this:
1276
1277 - *None*: the current figure
1278 - `.Figure`: the given `.Figure` instance
1279 - ``int``: a figure number
1280 - ``str``: a figure name
1281 - 'all': all figures
1282
1283 Notes
1284 -----
1285 pyplot maintains a reference to figures created with `figure()`. When
1286 work on the figure is completed, it should be closed, i.e. deregistered
1287 from pyplot, to free its memory (see also :rc:`figure.max_open_warning`).
1288 Closing a figure window created by `show()` automatically deregisters the
1289 figure. For all other use cases, most prominently `savefig()` without
1290 `show()`, the figure must be deregistered explicitly using `close()`.
1291 """
1292 if fig is None:
1293 manager = _pylab_helpers.Gcf.get_active()
1294 if manager is None:
1295 return
1296 else:
1297 _pylab_helpers.Gcf.destroy(manager)
1298 elif fig == 'all':
1299 _pylab_helpers.Gcf.destroy_all()
1300 elif isinstance(fig, int):
1301 _pylab_helpers.Gcf.destroy(fig)
1302 elif hasattr(fig, 'int'): # UUIDs get converted to ints by figure().
1303 _pylab_helpers.Gcf.destroy(fig.int)
1304 elif isinstance(fig, str):
1305 all_labels = get_figlabels()
1306 if fig in all_labels:
1307 num = get_fignums()[all_labels.index(fig)]
1308 _pylab_helpers.Gcf.destroy(num)
1309 elif isinstance(fig, Figure):
1310 _pylab_helpers.Gcf.destroy_fig(fig)
1311 else:
1312 _api.check_isinstance( # type: ignore[unreachable]
1313 (Figure, int, str, None), fig=fig)
1314
1315
1316def clf() -> None:

Callers

nothing calls this directly

Calls 7

get_figlabelsFunction · 0.85
get_fignumsFunction · 0.85
destroy_allMethod · 0.80
indexMethod · 0.80
destroy_figMethod · 0.80
get_activeMethod · 0.45
destroyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…