Minimalistic real-time rendering in Python

I have widely used python to extract data from various external equipment components (from arduins to oscilloscopes), and I'm looking for a simplified way to create material.

There are already answers to similar questions about stack overflow: What is the best real-time widget for wxPython?

With the greatest reference to this beautiful piece of code by Eli Benderski http://eli.thegreenplace.net/2008/08/01/matplotlib-with-wxpython-guis/

But the amount of code is much more complicated than what I'm looking for. I am looking for something very minimalistic that simply displays data in real time when it flows from the source - it does not need a graphical interface, switches, knobs and sliders or anything like that.

It seems that solutions like calling pylab.plot () or pylab.show () in a loop do not seem to give the correct behavior.

Does anyone have any suggestions?

+4
source share
3 answers

Besides the matplotlib examples given here, there is also wx.lib.plot and a few answers here: http://wxpython-users.1045709.n5.nabble.com/real-time-data-plots-td2344816.html

+1
source

Well, this is not wxPython's answer, but I used Chaco for this kind of thing, and it is pretty straight forward. A good example of a real-time spectrum analyzer , which may be similar to your use case and a good tutorial . So, if you are not attached to wxPython for other reasons, this might be worth a look.

+4
source

To use real-time graphics, you need to send signals to the GUI loop. If you use interactive mode (Ipython), you can also use streams.

I wrote several decorators to handle the GUI and threads in a very simple and clean way. They work for the QT backend. https://gist.github.com/Vrekrer/106c49a3ae6d420937aa

Sample code for Ipython will look like this:

#%pylab qt #https://gist.github.com/Vrekrer/106c49a3ae6d420937aa import QThreadDecorators import time @QThreadDecorators.GUI_Safe def myplot(x,y): #This will plot a new line for each call (ok for an example) plot(x, y, 'bo-') grid(True) @QThreadDecorators.AsQThread def myLoop(x): y = x * nan for i, xi in enumerate(x): #get some data time.sleep(1) y[i] = xi**2 #plot in real time myplot(x,y) #just call the function and it will run on a thread myLoop( arange(20) ) 
+1
source

Source: https://habr.com/ru/post/1397880/


All Articles