views:

1780

answers:

4

I would like to show a read time graph with one or two curves an up to 50 samples per second using Python and wxPython. The widget should support both Win32 and Linux platforms.

Any hints are welcome.

Edited to add:

I don't need to update the display at 50 fps, but up need to show up to 50 samples of data on both curves, with a reasonable update rate for the display (5..10 fps should be okay).

A: 

Maybe Chaco? I don't know if it can do 50 frames per second, but I saw in a demonstration how it did very smooth realtime plotting. It should definitely be faster than matplotlib.

nikow
A: 

If you want really something fast with 50 frames per second, I think you need something like PyGame and kind of talk directly to the display, not a plotting module.

Check the related threads:

Mapad
+4  A: 

Here's a sample of a dynamic plotter with wxPython and matplotlib. While not 50 FPS, it draws smoothly and quickly enough for most real-time data views:

http://eli.thegreenplace.net/2008/08/01/matplotlib-with-wxpython-guis/

Here's just the code paste: http://paste.pocoo.org/show/100358/

Eli Bendersky
I get "RuntimeError: xdata and ydata must be the same length" when trying to run the code paste
JcMaco
I think it's a problem with an older wxPy version. See comments in the blog post above
Eli Bendersky
+1  A: 

It's not difficult to create a C++ widget that would read from your data source, and truly update at 50 FPS. The beautiful thing about this approach is that very little (if any) Python code would be executing at 50FPS, it would all be in the C++, depending on how you hand your updated data to the widget.

You could even push an event handler into the custom real-time data viewer from the Python side, to handle all the mouse events and user interaction, and leave just the rendering in C++.

It would be a small C++ class that extends wxWidget's wxWindow class

class RealtimeDataViewer: public wxWindow { ...

and override OnPaint

void OnPaint(wxPaintEvent &WXUNUSED(event)) { ....

Then it would get a device context, and start drawing lines and shapes...

You would then have to take the .h file, and copy it to .i, and tweak it just a bit to make it a definition that SWIG could use to extend wxPython.

The build process could be handled by Python's own distutils using the following parameter to setup:

  ext_modules=[Extension('myextension', sources, 
                          include_dirs=includeDirs
                          library_dirs=usual_libs,
                          )],

It would be a few days work to get it looking great and working well... But it's probably the one option that would really accelerate your project into the future.

And all of this works well on Mac, Windows, and Linux.

wxPython is really a hidden Gem that would really take over the world with more professionally supported IDE / designer tools.

That said, try matplotlib first, it has lots of beautiful optimized rendering, and can do updates in real time too.

Jim Carroll
Thanks. I am actually trying to avoid going "down" into C++ for this. I don't need 50 FPS update rate, but I want to display 50 samples/s at a reasonable update rate (e.g. 10fps or event 5fps).
Ber
As long as you know the option exists... I think matplotlib will do a fantastic job with your current requirements.
Jim Carroll