On Mon, Nov 2, 2009 at 11:51 PM, Jae-Joon Lee <lee.j.j...@gmail.com> wrote:

> On Mon, Nov 2, 2009 at 10:52 PM, David Sanders <dpsand...@gmail.com>
> wrote:
> > from pylab import *
> >
> > ion()
> >
> > N = 1000
> > pos = zeros((N,2))
> >
> > figure(figsize=(8,8))
> > points, = plot(pos[:,0], pos[:,1], ',')
> > axis([-20,20,-20,20])
> >
> > for t in range(1000):
> >
> >     pos += uniform(-1,1,N*2).reshape(N,2)
> >     points.set_data(pos[:,0].copy(), pos[:,1].copy())
> >     draw()
>
> The Line2D object keeps the input data as a cache and only update it
> (recache) if the new data is different than the cached one.
> The problem in this particular case is that the cache is actually a
> *pos* itself. And modifying the pos in place, actually modify the
> cache in the Line2D object. Thus, set_data sees that the given data is
> identical to the cached one, and skip the recaching.
> I'm not sure what is the best approach here, and I defer the fix (or
> not) to others.
> Meanwhile, you can force the recaching with recache method. i.e., call
> points.recache() after set_data. You don't need to make a copy also.
> As a matter of fact, I think it will give you a best performance (but
> not tested) if you directly update the cached data and do not call
> set_data.
> Note that in this particular case, pos == cache, so you actually don't
> need to call get_data, but this is not a general case.
>
> posx, posy = points.get_data(orig=True)
>
> for t in range(100):
>    dx, dy = uniform(-1,1,N*2).reshape(2, N) # note the change in the shape
>    posx += dx
>    posy += dy
>    points.recache()
>    draw()
>
>
Dear JJ,

Many thanks for your answer -- "points.recache()" is exactly what I was
looking for to make my animations work.

It seems to me that this must be a reasonably common question, but I could
not find it in the documentation.
Perhaps it could be added to the animation cookbook?

Thanks and best wishes,
David.

PS: Apologies for the late reply -- I was travelling with difficult internet
access.
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to