How to not redraw a plot to avoid maxing out cpu usage

372 views
Skip to first unread message

Jason Mar

unread,
Jun 22, 2016, 8:20:56 PM6/22/16
to pyqtgraph
I'm currently working on a real time display system using pyqtgraph/anaconda3 and I'm having trouble optimizing the code to not clog the cpu. I'm currently plotting 600 points at all times * 2 sets of data per plot * 21 plots of data which is roughly 25000 points at all times. The code struggles to handle that many points (it crashes at 500s due to cpu maxing out at 100% running this code alone) and I'm willing to cut it to 300 points of data per dataset (5 minutes of real time data which is barely meeting our purpose of analyzing real time data), but even plotting 300 points clogs up ~60% of our cpu on an industrial computer which is not optimal since we're running other software at the same time (this code if possible can only take up ~20% of our cpu). This code reads data from another program that's processing the data, but for testing purposes a dummy file is being uses to simulate it.

 So I'm hoping that instead of redrawing the whole plot from scratch, there's an alternative to 'append' new points to an already drawn graph and only have to redraw the plot every 10 secs instead of every second (which is how often I receive new data). Y axis - data, X axis - time(seconds).

 If that's confusing I'm hoping for
0 - > 300 points hopefully being appended to avoid cpu clogging

when 300 points is plotted -> clear() -> plot the last 290 points and append the next 10 values

repeat until program ends. 

Any advice / alternatives will be much appreciated. I've attached my code for reference.

plot_21_baselines_ver2.py

vas...@gmail.com

unread,
Jun 23, 2016, 2:34:01 AM6/23/16
to pyqt...@googlegroups.com
There is lack of other files and directory you uses so it can't be reproduced, but you could try that instead of .clear() use .setData(..., clear=True). Also try to add QtGui.QApplication.processEvents() in your update function, or make new QTimer with lower value, just for a new function with QtGui.QApplication.processEvents().

--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/027fac66-26ce-4e70-a198-f3cec1be25dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jason Mar

unread,
Jun 24, 2016, 5:05:41 PM6/24/16
to pyqtgraph
Hi,

Thanks for responding! It would be pretty complicated if I were to post a working copy of my code (at least 10 other files), I just wanted to show the code that's just processing the points. I couldn't find any information on QtGui.Qapplication.processEvents() on google, can you explain what it does and how should I implement it?
Reply all
Reply to author
Forward
0 new messages