Live Data Monitor: PyQtGraph

I am working on a project where I will have to analyze the signals coming from the device. I have a library that receives data from my device. At the moment I am collecting data and then drawing them. I am interested in creating a live data monitor that can plot in real time. When searching, I realized that PyQtGraph is perfect for this task. I am not familiar with Qt, so I am looking for examples that I can change for my needs. Some examples provided in the PyQtGraph docs update the chart in real time, BUT I need something like a real-time monitor, where the chart moves to the right as it continues to receive data.

If this is something like a known continuous function, I can update the input x - w*twith tas time to make the wave move to the right. But this is discrete data, so I'm not sure how to make it work using PyQtGraph. Therefore, it would be great if someone could give some guidance on how to do this.

At the moment, this is what I have

the code

app = QtGui.QApplication([])
#mw = QtGui.QMainWindow()
#mw.resize(800,800)

win = pg.GraphicsWindow(title="Basic plotting examples")
win.resize(1000,600)
win.setWindowTitle('pyqtgraph example: Plotting')

# Enable antialiasing for prettier plots
pg.setConfigOptions(antialias=True)

p6 = win.addPlot(title="Updating plot")
curve = p6.plot(pen='r')
X_axis = numpy.linspace(0,100,12800)
#'data' is my required y_axis containing 12800 values
ydata = np.array_split(data,50)
xdata = np.array_split(X_axis,50)
ptr = 0
def update():
    global curve, data, ptr, p6
    curve.setData(xdata[ptr%50],ydata[ptr%50])
    ptr += 1
timer = QtCore.QTimer()
timer.timeout.connect(update)
timer.start(1000)

This is an update of data for every 2 second interval, but I want it to move to the right.

+4
source share
1 answer

To scroll through the plot, you have three options:

  • Scroll through the raw data and redraw (see numpy.roll )

    curve = plotItem.plot(data)
    data = np.roll(data, 1)  # scroll data
    curve.setData(data)      # re-plot
    
  • Move the plot curve so that it slides in view:

    curve = plotItem.plot(data)
    curve.setPos(x, 0)  # Move the curve
    
  • ,

    curve = plotItem.plot(data)
    plotItem.setXRange(x1, x2)  # Move the view
    

- ( ) :

+3

Source: https://habr.com/ru/post/1544422/


All Articles