问题
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
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
回答1:
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.
来源:https://stackoverflow.com/questions/20401057/matplotlib-close-does-not-close-the-window