Live Data Monitor: PyQtGraph
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:
user1955184
Updated on June 14, 2022Comments
-
user1955184 about 2 years
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
witht
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.
-
user1955184 about 10 yearsThanks! In the example you suggested update1 works fine, but there is an error before update2, "plotItem has no attribute setLimits" . Can you please look into that?
-
Luke about 10 yearssetLimits is only available in the development version.
-
user1955184 about 10 yearsThe moving plot seems to work fine,but the Y axis seems to auto adjust the range erratically. So it looks like the graph is sliding up and down as well. I tried to use setYRange but the problem is that, the graph becomes too small and concise,it doesn't look good and small variations cannot be seen clearly. Is there a way where I can get best of both the worlds?
-
user1955184 about 10 yearsLet's say I have minimum value of 1850 and maximum value of 2500. My seYRange is from 1800 to 2500. Most of my data is in 2300-2400 data range, but sometimes it goes to 2200s and once it goes to 1850. So my graph's Y-axis is split into 7 regions (from 1800-2500). And the graph mostly resides only in the 2300-2400 region -which makes it look very small. The Y-interval is 100 units. Is it possible to make it a bit more small - like 25 units? That is instead of 2000-2100-2200,I want 2000-2025-2050...
-
Luke about 10 yearsAh, I see--you don't want the data larger, you just want the ticks to be more dense. In that case, have a look inside
graphicsItems/AxisItem.py
, in the__init__()
method, you will seeself.style['textFillLimits']
, which is a set of heuristics used to determine the optimal tick spacing. You can modify those values on any AxisItem.. -
SriramK89 about 9 yearsHey @Luke.. I am also trying to do the same thing as given in the question. But I am unable to get it working in my machine after installing 'pyqt4'. Please help me for installation of this one.