matplotlib close does not close the window

Deadly 提交于 2019-12-11 05:59:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!