我正在实施基于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)
定时器应该每100ms发射一次。但是当我检查时,定时器周期超过100毫秒。因此情节感觉较慢。更新功能处理时间小于100ms。 pyqtgraph的google小组的Luke说,重新绘制GUI需要额外的时间。
我启用了一个点击处理程序,可以最大化单个图并隐藏所有其他图。现在计时器正常启动。我的猜测是,由于Qt需要更少的时间来重新绘制单个绘图,即使它最大化(可能是因为像素级别更改)。
所以我的问题是,我如何优化或增强我的代码,以便当我在网格视图中一起查看所有图时,图正确更新。如何减少重绘时间?或者有更好的解决方案吗?
我已经分析了我的代码,您可以在this pastebin页面查看它。
我试过“disableAutoRange”。但仍然不尽如人意。