What is the best real time plotting widget for wxPython?

后端 未结 5 1073
旧巷少年郎
旧巷少年郎 2020-11-30 04:35

I would like to show a real 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 platf

5条回答
  •  感情败类
    2020-11-30 04:49

    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.

提交回复
热议问题