Matplotlib python show()立即返回 [英] Matplotlib python show() returns immediately

查看:145
本文介绍了Matplotlib python show()立即返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的python脚本,该脚本在同一图中绘制了一些图形.所有图形都是由draw()创建的,最后我调用show()函数进行阻止.

I have a simple python script which plots some graphs in the same figure. All graphs are created by the draw() and in the end I call the show() function to block.

该脚本曾经用于Python 2.6.6,Matplotlib 0.99.3和Ubuntu 11.04.试图在Python 2.7.2,Matplotlib 1.0.1和Ubuntu 11.10下运行它,但是show()函数立即返回,而无需等待杀死该数字.

The script used to work with Python 2.6.6, Matplotlib 0.99.3, and Ubuntu 11.04. Tried to run it under Python 2.7.2, Matplotlib 1.0.1, and Ubuntu 11.10 but the show() function returns immediately without waiting to kill the figure.

这是一个错误吗?还是一项新功能,我们将不得不更改脚本?有什么想法吗?

Is this a bug? Or a new feature and we'll have to change our scripts? Any ideas?

它的确在交互模式下(例如python -i ...)使图保持打开状态,但以前没有这种情况就可以工作,并尝试在菜单中包含plt.ion().脚本并在正常模式下运行它,但是没有运气.

It does keep the plot open under interactive mode, i.e., python -i ..., but it used to work without that, and tried to have plt.ion() in the script and run it in normal mode but no luck.

推荐答案

我也遇到了同样的问题,这是由于在Figure对象而不是pyplot对象上调用show()引起的.

I had this same problem, and it was caused by calling show() on the Figure object instead of the pyplot object.

错误的代码.使图形在屏幕上短暂闪烁:

Incorrect code. Causes the graph to flash on screen for a brief instant:

    import matplotlib.pyplot as plt

    x = [1,2,3]
    y = [5,6,7]

    fig = plt.figure()
    plt.plot(x, y)

    fig.show()

最后一行应如下所示以显示图形,直到将其消除:

Last line should be as follows to show the graph until it is dismissed:

    plt.show()

这篇关于Matplotlib python show()立即返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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