Python bridge plotting example

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

Attachment: python_bridge_plotting_demo.xml (1.87 KB)

Python files attached

Attachments:

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

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

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