matplotlib关闭不会关闭窗口 [英] matplotlib close does not close the window

查看:538
本文介绍了matplotlib关闭不会关闭窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到当我运行时:

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

最后一条语句没有完全关闭该图。该图变暗,内容消失,但该图一直保留在屏幕上,直到我退出IPython为止,如下所示

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

                     

                     

我正在使用最新的在Linux 64位上使用Anaconda发行版的稳定版本的matplotlib( 1.3.1 ),我使用 ssh -X 进行远程连接。

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


推荐答案

您必须指定您想要关闭的数字。如果要关闭所有它们:

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()

此外,从<一个href = https://stackoverflow.com/questions/11140787/closing-pyplot-windows>另一个SO问题:


请记住, plt.show()是一个阻止函数,因此在上面使用的示例代码中, plt.close()

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.

您可以使用 plt.ion() 在代码的开头使其无阻塞,尽管这还有其他含义。

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

这篇关于matplotlib关闭不会关闭窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆