matplotlib close does not close the window

12,779

you have to specify wich figure you want to close. In case you want to close all of them:

pl.close('all')

Also, there is a way to just clear but not close a figure:

pl.clf()

Also, seen below from another SO question:

Remember that plt.show() is a blocking function, so in the example code you used above, plt.close() isn't being executed until the window is closed, which makes it redundant.

You can use plt.ion() at the beginning of your code to make it non-blocking, although this has other implications.

Share:
12,779

Related videos on Youtube

Josh
Author by

Josh

Engineering manager at a mid-sized tech company

Updated on June 04, 2022

Comments

  • Josh
    Josh almost 2 years

    I have noticed that when I run:

    import pylab as pl
    pl.ion()
    # Plot something
    pl.show()
    pl.close()
    

    The last statement does not fully close the Figure. The figure goes dark, and the contents go away, but the Figure stays on the screen until I exit IPython as shown below

                          enter image description here

    I am using the latest stable version of matplotlib (1.3.1) using an Anaconda distribution, on Linux 64 bit, and I connect remotely using ssh -X.

    The backend I am using is below:

    backend : QT4Agg
    backend.qt4 : PySide