如何制作基于pyqtgraph的实时绘图fas

2024-10-02 20:39:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在实现一个基于pyqtgraph的ECG显示应用程序。在

它在一个网格中更新24个子窗口。每个子批次有4个ECG通道,每个通道对应的缓冲区大小为2500个整数。在

一个专用的UDP线程从网络获取数据并写入python队列,队列由QTimer定期调用的函数读取。一些相关的代码片段:

win = pg.GraphicsWindow()

#Create the GRID using the constructor and win.nextRow
for x in range(0, (config_data.num_of_devices / config_data.gridwidth)):
    for y in range(0, config_data.gridwidth):
        devicenum = (config_data.gridwidth * x) + y
        devicehandle[devicenum] = Deviceplot(
            devicenum, tpen, dataq[devicenum], win, config_data)
    win.nextRow()


class Deviceplot(object):

    def __init__(self, device, tpen, dataqueue, win, config_data):
        self.p = win.addPlot()
        self.curve1 = self.p.plot(self.data1, pen=self.tpen)

def update():
    for x in range(0, config_data.num_of_devices):
        devicehandle[x].getdata()
        devicehandle[x].update1()
        devicehandle[x].update2()
        devicehandle[x].update3()
        devicehandle[x].update4()

timer = pg.QtCore.QTimer()
timer.timeout.connect(update)
timer.start(100)  

定时器应该每100毫秒触发一次,但是我检查的时候,定时器的周期超过了100毫秒。因此,情节感觉比较慢。更新函数的处理时间不到100ms,pyqtgraph的googlegroups的Luke说,重新绘制GUI需要额外的时间。在

我启用了一个click处理程序,它最大化了单个绘图,并隐藏了所有其他绘图。现在计时器正常启动。我的猜测是,由于Qt需要更少的时间来重新绘制一个单独的绘图,即使它最大化了(可能是由于像素级的变化较少)。在

所以我的问题是,如何优化或增强我的代码,以便当我在网格视图中一起查看所有的绘图时,绘图会得到正确的更新。如何减少重新喷漆的时间?还是有更好的解决办法?在

更新

我已经分析了我的代码,您可以在thispastebin页面查看它。在

我试过“禁用自动导航”。但仍然不能令人满意。在


Tags: 代码inselfconfig绘图fordata时间