matplotlib.pyplot.close#

matplotlib.pyplot.close(fig=None)[source]#

Close a figure window, and unregister it from pyplot.

Parameters:
figNone or int or str orFigure

The figure to close. There are a number of ways to specify this:

  • None: the current figure

  • Figure: the givenFigure instance

  • int: a figure number

  • str: a figure name

  • 'all': all figures

Notes

pyplot maintains a reference to figures created withfigure(). Whenwork on the figure is completed, it should be closed, i.e. deregisteredfrom pyplot, to free its memory (see also :rc:figure.max_open_warning).Closing a figure window created byshow() automatically deregisters thefigure. For all other use cases, most prominentlysavefig() withoutshow(), the figure must be deregistered explicitly usingclose().

Examples usingmatplotlib.pyplot.close#

Pong

Pong

Multipage PDF

Multipage PDF

Multiprocessing

Multiprocessing

Tight layout guide

Tight layout guide