Real-time graphs

Jeremy O'Donoghue jeremy at o-donoghue.com
Fri May 14 14:37:53 EDT 2004


I'm the maintainer of the wx backend for matplotlib.

My original reason for getting involved with matplotlib was related to
real-time graphing and analysis, so hopefully I can give you some
indications on performance.

John Hunter <jdhunter at ace.bsd.uchicago.edu> wrote in message news:<mailman.491.1084399021.25742.python-list at python.org>...
> >>>>> " " ==   <snrkiwi-lists at yahoo.com> writes:
> 
>      > I've trolled the lists, FAQs, and Net as a whole, but can't
>      > find anything definitive to answer this.
> 
>      > We're looking for real-time graph capability (bar, line, etc),
>      > so that we can display telemetry from a robot system.  There
>      > are a bunch of packages out there, but many seem to provide
>      > only static graphs (e.g. for scientific, financial data,
>      > etc). Does anyone currently display real-time telemetry using
>      > Python? Can anyone provide any suggestions?
> 
> You can do animated graphs with matplotlib - see the examples in the
> src distribution anim.py, system_demo.py and dynamic_demo.py.  On my
> computer (fairly fast) I can get 80-frames per second continually
> redrawing the system_monitor figure after updating the data
> (admittedly a fairly simple graph) using the antigrain/gtk backend.

There is a (rather primitive) example (dynamic_demo_wx.py) supplied in
the default matplotlib install, which indicates the basics of
embedding a dynamically updated matplotlib plot in a wxFrame (the code
is essentially identical in the case of a wxPanel). Having just run
the sample, I should note that some of the event handling needs
tidying up, but for someone experienced in wx this should be a breeze.

> I'm in the process of making some optimizations that will provide some
> additional gains, but more work will be required to support real time
> charting, especially for more complicated plots.  Depending on your
> needs and size of plots, however, it may be fast enough.

My application displays two separate plots, with multiple axes. One
indicates (in real-time) data throughput at the different layers, for
a GPRS mobile phone, and the other provides TCP/IP throughput.

The application is generally executed on reasonably modern laptops,
and you should bear in mind that the main overhead is parsing the
logging output to obtain the desired information (I also display
signalling information in a text window).

The main issue under wx is that the wx backend uses double buffering,
and there seems to be a finite time to blit the frame buffer to the
screen. In my application, I'm seeing 5-10 updates per second. My
estimate is that an application with lower preprocessing requirements
would get about 4x the update rate.

In my case, I actually wait until I have 16 new points before updating
the chart (which gives me my 5-10 Hz updates), but I'm well aware that
this will not be adequate for some applications.

The fastest solution, under Windows (but not Linux or Mac), using wx,
is not to use double buffering, but to use the GDI-style commands. The
earliest versions of backend_wx worked this way (but, obviously,
flickered somewhat). If this is very important, I can indicate what
would be needed to bring back this functionality (basically replacing
wxMemoryDC with wxPaintDC, if memory serves).

The signal processing in matplotlib is actually very fast indeed,
courtesy of Numeric. I believe that you would be hard put to go faster
in C. The key issue is in optimising your updating, to minimise the
number of redraws.

Overall, it has served me very well, although if your performance
needs are much beyond what I have noted, you probably are better off
with Labview controls, assuming you can run to the price.

One other thing I'd point out (as John is too modest) is that
matplotlib is being very actively developed as a truly cross platform
solution (I originally developed under Linux, now Mac, but deploy
under Windows at work), with quite a number of contributors. This
means that you can rely on support of an active community that
typically fixes bugs in a day or two.

It's also pretty well documented (although the 'matlab' interface is
much better documented than the object oriented interface, as most
contributors make more use of that approach.

If you decide to go with Matplotlib, I'll try to give you some
pointers.

Regards

Jeremy



More information about the Python-list mailing list