Optimal approach for real-time plotting on embedded device

81 views
Skip to first unread message

James Ross-Smith

unread,
Aug 21, 2017, 4:22:14 AM8/21/17
to pyqtgraph

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

James Ross-Smith

unread,
Aug 21, 2017, 6:12:31 PM8/21/17
to pyqt...@googlegroups.com
Just thinking out loud here: the above section of code is already being executed on a separate thread, in the hope of freeing up the main thread. The main thread receives a signal when the above processing is complete, and then updates the plot on the UI.

In other applications, I've used an external plotting file with matplotlib, which returns the plot has bytes to the main application/thread, which worked really well. Is this an option with pyqtgraph? If so, would running the plot as an external file and returning the plot as bytes be faster than the above approach? I can't imagine it would be, as the above approach appears to be the most direct.

Another question: my entire application is based on the use of QtWidgets.QOpenGLWidgets; does this mean the viewPort for the PlotWidget() automatically uitilises OpenGL rendering? I tried setting the viewPort rendering to OpenGL explicitly, but was receiving the "EGLFS: opengl windows cannot be mixed with others" error.

Any guidance/clarification would be greatly appreciated as always!

Jamie

--
You received this message because you are subscribed to a topic in the Google Groups "pyqtgraph" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pyqtgraph/3CPo_qm071Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pyqtgraph+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/475a8259-49dd-4e7f-a4b1-889d1dfd52ff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

James Ross-Smith

unread,
Aug 27, 2017, 5:59:12 PM8/27/17
to pyqt...@googlegroups.com
I've not been able to make any progress on this. Can anyone specify if the above example code I've posted would make use of OpenGL rendering? Given the performance I'm currently experiencing I'm almost certain the plot is being executed with software rendering. When I try and set the viewPort to OpenGL rendering explicitly I receive the "EGLFS: opengl windows cannot be mixed with others" error. Is there any way to make this work with pyqtgraph, or am I better off using vispy?
Reply all
Reply to author
Forward
0 new messages