python - 在 PyQtGraph 中显示平均值

标签 python pyqtgraph

我很好奇如何使用 average feature在 PyQtGraph 中(可通过上下文菜单访问 Plot Options > Average )。

我期望发生的事情:
我有一个曲线图,它不断更新。当我激活平均值时,我可以选择对曲线进行平均和显示的轨迹数。我最终得到了一条曲线,它更新得更顺畅。禁用原始(非平均)曲线也很好。例如,此功能在现代示波器中非常常见。

会发生什么:
我打开例子Benchmarks > Line Plot update并选择 Average .然后原始曲线继续更新(白色),出现一条新曲线,它是我激活平均按钮时曲线的副本(我认为)。下面的字段Average保持空。

Example with Averaging

我有一种感觉,我误解了这个平均功能是如何工作的。在 source code看起来您可以平均指定参数,但我不知道如何定义一个。

任何人都可以为我解决这个困惑,或者这个功能是否记录在某个地方(我找不到任何东西)?

最佳答案

通过勾选按钮,图形上的多条曲线的平均曲线将用绿色笔绘制。
如下图,绿色曲线是绘制两条白色曲线的平均数据。
enter image description here

import sys
from PyQt5 import QtWidgets, QtCore
import pyqtgraph as pg


class Draw_interface(QtWidgets.QMainWindow):
    def __init__(self):
        super(Draw_interface, self).__init__()
  
        p1 = pg.PlotWidget(name = "Plot1")
        
        # Draw charts
        y = [2.2, 3.0, 1.3, 2.5, 1.9, 2.2, 5.5, 6.6]
        y2 = [2.3, 3.3, 2.8, 2.2, 3.3, 3.1, 2.8, 4.4]
        p1.plot(y)
        p1.plot(y2)

        l = QtWidgets.QVBoxLayout()
        l.addWidget(p1)
        w = QtWidgets.QWidget()
        w.setLayout(l)
        self.setCentralWidget(w)
        self.setStyleSheet("QWidget { background-color: black; }")
    
def main():
    QtWidgets.QApplication.setAttribute(QtCore.Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
    app = QtWidgets.QApplication(sys.argv)
    
    main = Draw_interface()
    main.show()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()

关于python - 在 PyQtGraph 中显示平均值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40850151/

相关文章:

python - 使用 matplotlib 和 Pandas DataFrame 绘制数据覆盖图

Python-删除字符串中的重复字母

python - "Can' t 从安装目录获取安装脚本的一致路径”

python - 使用 pyqtgraph 实时绘制许多子图

python - pyqtgraph:在缩放时保持 TextItem 的恒定位置

python - PyQtGraph 堆积图方法

python - 创建一个仅包含原始短语中第一次出现的字母的函数

python - 为什么断言在抽象类中不起作用?

php - 在 PI 中从浏览器执行 GPIO python

python - 使用PyQtGraph绘制Datetime对象