I am working on a project where I will have to analyse signals coming from a device. I have a library working which gets me data from the device. As of now, I am collecting the data and then plotting it. I am interested in building a live data monitor which can plot a graph in real time. Upon searching, I figured out PyQtGraph is ideal for the task. I am not familiar with Qt, so I am looking for examples which I can modify to my needs. Some examples given in PyQtGraph docs update the plot real-time BUT I need something like a live monitor- where the graph is moving towards the right as it keeps receiving data.
If it it something like a known continuous function, I can update the input x - w*t
with t
being the time so as to get the wave moving towards right. But this is discrete data, so I am not sure about how to get it working using PyQtGraph. So it would be great if someone could give some pointers on how to go about.
As of now this is what I have
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 updating the data for every 2-second interval, but I want it to move towards the right.
To make a plot scroll, you have three options:
Scroll the raw data and re-plot (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 across the view:
curve = plotItem.plot(data)
curve.setPos(x, 0) # Move the curve
Move the view region such that the plot curve appears to scroll
curve = plotItem.plot(data)
plotItem.setXRange(x1, x2) # Move the view
The scrolling-plots example (currently only in the development version) demonstrates each of these: