PyQtGraph 打开然后立即关闭 [英] PyQtGraph opening then closing straight away

查看:47
本文介绍了PyQtGraph 打开然后立即关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行文档中的一些基本代码

I'm running some basic code from the documentation

import pyqtgraph as pg
import numpy as np
x = np.arange(1000)
y = np.random.normal(size=(3, 1000))
plotWidget = pg.plot(title="Three plot curves")
for i in range(3):
    plotWidget.plot(x, y[i], pen=(i,3))

但由于某种原因,窗口打开然后立即关闭,我只看到它的闪烁.是否有某种功能可以使窗口保持打开状态?

But for some reason the window open then closes straight away, i just see a flicker of it. Is there some sort of function in which i can keep the window open?

推荐答案

问题是 Python 进程在 for 循环的最后一次迭代后结束,因此也终止了小部件.您可以使用 -i 开关在执行脚本后进入交互式 Python 解释器,该脚本保留在脚本执行期间实例化的所有对象:

The problem is that the Python process finishes after the last iteration of the for loop and thus also terminates the widgets. You can use the -i switch in order to enter the interactive Python interpreter after executing the script which retains all objects that were instantiated during execution of the script:

python -i /path/to/script.py

诚然,这是一种解决方法,pyqtgraph 可能有一种原生"方式来实现这一点(例如 matplotlib.pyplot 中的 show 函数code> 默认情况下这样做)但是我找不到 pyqtgraph 的类似函数.

Admittedly this is rather a workaround and pyqtgraph probably has a "native" way of achieving this (such as the show function from matplotlib.pyplot does it by default) however I couldn't find a similar function for pyqtgraph.

这篇关于PyQtGraph 打开然后立即关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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