G'day,
I've written a basic line plotter which holds ~10s (600 data points at 60Hz) worth of data, which continuously scrolls to the left to mimic a real-time data feed.
I've done this by populating a list, which appends new data each iteration, whilst removing the same number of data points from the beginning of the list. I've also added some threshold lines (an upper and lower), as well as an x-axis line. The below code should give an indication as to the approach I've taken:
Plot = pyqtgraph.PlotWidget()
DataList = []
for x in range(0, 600):
DataList.append(DataSource[x])
Plot.clear()
curve = Plot.plot([float(i) for i in DataList], clickable=False)
LowerThresholdList = []
UpperThresholdList = []
XAxisList = []
for x in range(0, 600):
LowerThresholdList.append(float(LowerThresholdValue))
UpperThresholdList.append(float(UpperThresholdValue))
XAxisList.append(0)
Plot.plot(LowerThresholdList, pen=(255,165,0))
Plot.plot(UpperThresholdList, pen=(255,0,0))
Plot.plot(XAxisList)
I played with InfiniteLines in place of the threshold and x-axis lines, but prefer how the above lines don't reach the y axis, whereas the InfiniteLine continues all the way to the axis (as the name would suggest).
When I run the above on my development machine, it works perfectly, with the plot updating and scrolling at the full 60Hz refresh rate. When I deploy the software to my embedded device (currently prototyping on a Raspberry Pi 2 with EGLFS and OpenGL-enabled), the entire UI becomes sluggish beyond about 1Hz. My question: is the above approach the best way of achieving a real-time scrolling line plot? Is replacing the threshold and x axis plots with InfiniteLines a faster/more efficient approach? The aim is to have full 60Hz scrolling updates of the data on the embedded device; if the above approach/selection of PlotWidget/etc. isn't suitable, can you please point me in the right direction?
Many thanks,
Jamie