4

I've been using python extensively to extract data from various external pieces of equipment (ranging from arduinos to oscilloscopes), and I'm looking for a simplistic way to plot stuff.

There's already some answers to similar questions on stack overflow: What is the best real time plotting widget for wxPython?

With most pointing to this fine piece of code by Eli Bendersky http://eli.thegreenplace.net/2008/08/01/matplotlib-with-wxpython-guis/

But the scope of the code is far more complicated that what I'm looking for. I'm looking for something rather minimalistic that just plots the data in real-time as it streams from a source -- it doesn't need a GUI, radio buttons, knobs and sliders, or anything like that.

It seems that solutions such as calling pylab.plot() or pylab.show() in a loop doesn't seem to give the correct behavior.

Does anyone have suggestions?

1

1 Answer 1

1

To use real time plotting you need to send signals to the GUI loop. If you use interactive mode (Ipython) then you might also like to use threads.

I have written some decorators to handle the GUI and threading in a really easy and clean way. They work for the QT backend. https://gist.github.com/Vrekrer/106c49a3ae6d420937aa

A 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) )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.