Python bridge plotting example

Christopher Stawarz's Avatar

Christopher Stawarz

02 May, 2016 03:39 PM

Hi Mark,

As you requested last time we spoke, I've put together a small example of how I generate trial-by-trial plots using the Python bridge.

The attached files are an adaption of the MATLAB window demo to Python. The experiment generates random values (10 per trial over 10 trials) and stores them in the variable rand_var. The Python script draws a histogram of these values, updating the plot whenever new values are received. The script can be run via the client or server bridge. (In the latter case, the conduit resource is assumed to be named server_conduit.)

The Conduit class defined in common.py provides a generic framework for online plots. It inherits from mworks.conduit.IPCAccumClientConduit, which accumulates requested events between "start" and "stop" events, then delivers them as a group to an event handler. (The Conduit class expects variables named start and stop for this purpose, but this can be changed to any two variables you prefer.)

The main benefit of the Conduit class is that it handles running of the application main loop (starting and stopping it as needed to handle new events). This keeps the matplotlib window responsive to user input, allowing you to pan, zoom, or whatever.

If you have any questions, please let me know.

Cheers,
Chris

  1. Support Staff 1 Posted by Christopher Sta... on 02 May, 2016 03:40 PM

    Christopher Stawarz's Avatar

    Python files attached

  2. 2 Posted by mhisted on 02 May, 2016 05:22 PM

    mhisted's Avatar

    Thanks, Chris. I will look at this, it's very helpful.

    What Python distribution/version are you using? Can I test it on a recent version of anaconda with Python 2.7? That is our preferred option now.

    Mark

  3. Support Staff 3 Posted by Christopher Sta... on 02 May, 2016 07:03 PM

    Christopher Stawarz's Avatar

    What Python distribution/version are you using? Can I test it on a recent version of anaconda with Python 2.7? That is our preferred option now.

    I normally use the system Python (/usr/bin/python2.7), but if you're running the script via the server conduit, any Python 2.7 should be fine. (I just tested it with Anaconda, and it worked as expected.)

    Chris

  4. 4 Posted by mhisted on 02 May, 2016 07:21 PM

    mhisted's Avatar

    Great. We will need scipy for things like smoothing data, and scipy isn't installed with the system python. And it's a pain to install last I checked, I believe it needs Fortran code compiled. Anaconda is a good solution for us.

    Mark

  5. Christopher Stawarz closed this discussion on 13 May, 2016 12:36 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac