首页 > 解决方案 > PyQt/Matplotlib 动画的最大 fps 是多少?

问题描述

在我的 Python 项目中,使用 PyQt 图形小部件并从第三方硬件中提取数据,我试图最大限度地提高更新速度以显示实时读数。是否有我应该追求的基准,或者它与我可以操纵的另一个自变量有直接关系。

'代码'

    #graphing window class, called by each object instantiation

类 MainWindow(QtWidgets.QMainWindow):

def __init__(self,chan,*args, **kwargs):
    super(MainWindow, self).__init__(*args, **kwargs)
    self.chan=chan
    self.graphWidget = pg.PlotWidget()
    self.setCentralWidget(self.graphWidget)
    self.x = list(range(100))  # 100 time points
    self.y = [0 for _ in range(100)]  # 100 data points
    self.graphWidget.setBackground('w')
    self.setWindowTitle("Channel " + (str)(self.chan))
    self.setGeometry((500*self.chan), 50, 500, 300)
    pen = pg.mkPen(color=(255, 0, 0))
    self.data_line =  self.graphWidget.plot(self.x, self.y, pen=pen)
    #closing the graph window(with the drop down menu)
    self.timer = QtCore.QTimer()
    self.timer.timeout.connect(self.update_plot_data)
    self.timer.start()

#Eventual call to IsTriggered()
def update_plot_data(self):
    if (adc_list[self.chan].used):
        d = adc_list[self.chan].chip.read(f)
        data_set[self.chan].append(d)
        #d = signal.decimate(d, adc_list[self.chan].downsample_factor)
        global clock_divider
        global user_scaling
        clock_divider[self.chan]+=1
        if (clock_divider[self.chan]==clock_divs[self.chan]):
            clock_divider[self.chan]=0
            self.x = self.x[1:]  # Remove the first y element.
            a=(self.x[-1]+1)
            self.x.append(a)
            self.y = self.y[1:]  # Remove the first
            self.y = np.append(self.y, np.mean(d)*user_scaling[self.chan])
            self.data_line.setData(self.x, self.y)
 

标签: pythongraphpyqt

解决方案


推荐阅读