I'm trying to use matplotlib for animating data as it is received from an
online source (online in the algorithmic sense not internet:). I'd like
the graph plot to be updated with high frequency since the data changes
rapidly. I've used the BufferRegion with copy_from_bbox / restore_region
and it speeds up the plotting considerably but alas it's still not good
enough (with a large number of graphs and a large number of data points in
Well, if you need your plot updated with very high frequency, MPL may
not be your tool of choice.
Anyhow, my first recommendation is not to update the plot frequently.
I mean, do you have to update the plot for every changes? Can you
update it every 10th change, for example?
What I'd like to do is to utilize the fact that the animation is updated
in a predictable fashion (i.e., scrolling off the screen to the left as
new data arrives) in order to speed up the animation. The idea would be to
copy the right 99% of the graph (or some other fraction) via some kind of
function similar to copy_from_bbox, move it 1% to the left and then plot
the new 1% of the data. The problem is that as far as I can tell the
copy_from_bbox/restore_region does not actually allow changing the area in
which it is restored. I've mucked around in the source files a bit but to
My question is then:
1. Is there some other way to copy everything enclosed in a Bbox? or
2. Is there some way to modify the region in which data reappears when
3. Perhaps I'm missing something?
I'm sure someone else has done this since it seems pretty natural and
useful for a variety of applications.
I'm attaching a patch that might do what you want to do.
It implements a "restore_bbox2" method which restores a subset of the
saved background at a specified position.
A small example is also attached (it is based on the gtk backend).
I, personally, am not sure if this kind of feature is useful. If you
shift part of your figure, you have to be careful not to mess up with
the coordinate system. And also be careful about what to be shifted
and what to be not (e.g., ticks).
If others find this useful, I'll commit this to the trunk with some
restore_region2.diff (3.62 KB)
animation_blit_gtk2.py (1.96 KB)
On Mon, Apr 20, 2009 at 4:34 PM, Elan Pavlov <elan@...1166...> wrote:
"If stupidity got us into this mess, why can't it get us out?"
- Will Rogers
Stay on top of everything new and different, both inside and
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today.
Use priority code J9JMT32. http://p.sf.net/sfu/p
Matplotlib-users mailing list