4
votes

I'm curious on how to use the average feature in PyQtGraph (accessible through the context menu Plot Options > Average).

What I would expect to happen: I have a plot with a curve, that continuously updates. When I activate average I can choose over how many traces the curve is averaged and displayed. I end up with a curve, that updates more smoothly. It would also be good to disable the original (unaveraged) curve. This functionality is very common in modern oscilloscopes for example.

What happens: I open the example Benchmarks > Line Plot update and select Average. Then the original curve continues updating (white), and a new curve appears which is a copy of the curve at the time when I activated the average button (I think). The field below Average stays empty.

Example with Averaging

I have the feeling that I misunderstood how this averaging functionality works. In the source code it looks like you can average over a specified parameter, but I have no idea how to define one.

Can anybody resolve this confusion for me, or is this feature documented somewhere (I cannot find anything)?

1

1 Answers

0
votes

By checking the button, an average curve of multiple curves on the graph will be plotted with a green pen.

Show as below, the green curve is plotting the average data of the two white curves. 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()