471,350 Members | 1,592 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

Animations with matplotlib?

I'm trying to make an animation with matplotlib. The problem:
whenever I try to rescale or move the plot with the buttons of
plotting window, the animation stops. My system is Debian Woody and
python-2.3 with matplotlib-0.32. I'm a total newbie with matplotlib
(I installed it yesterday), so what am I doing wrong? An example code
below:

------------------------------------------
#!/usr/bin/env python2.3

import matplotlib.matlab
import gtk
import Numeric

fig = matplotlib.matlab.figure(1)
ind = Numeric.arange(60)
x_tmp=[]
for i in range(100):
x_tmp.append(Numeric.sin((ind+i)*Numeric.pi/15.0))

X=Numeric.array(x_tmp)
lines = matplotlib.matlab.plot(X[:,0],'o')

def updatefig(*args):
updatefig.count += 1
if updatefig.count>59: updatefig.count=0
lines[0].set_data(ind,X[:,updatefig.count])
fig.draw()
return gtk.TRUE

updatefig.count=-1

gtk.timeout_add(200,updatefig)
matplotlib.matlab.show()
-------------------------------------------------

--
Best regards,
Pekko

Jul 18 '05 #1
1 4829
>>>>> "Pekko" == Pekko Piirola <pe***********@helsinki.fi> writes:

Pekko> I'm trying to make an animation with matplotlib. The
Pekko> problem: whenever I try to rescale or move the plot with
Pekko> the buttons of plotting window, the animation stops. My
Pekko> system is Debian Woody and python-2.3 with matplotlib-0.32.
Pekko> I'm a total newbie with matplotlib (I installed it
Pekko> yesterday), so what am I doing wrong? An example code
Pekko> below:

Cute code, looks like the beginnings of a digital oscilloscope....

You have discovered a bug. The Lines2D class goes to great pains to
not plot data outside the view limits and caches a 'clipped' version
of the data set. This cache should have been cleared by the set_data
method. Since set_data is rarely used directly, this bug hasn't been
reported before. It's an easy fix.

In the matplotlib.lines.py module, go to the Line2D.set_data method
(line 74 in the 0.32 release) and replace it with:

def set_data(self, x, y):
try: del self._xc, self._yc
except AttributeError: pass

self._x = asarray(x, Float)
self._y = asarray(y, Float)
if len(self._y)==1 and len(self._x)>1:
self._y = self._y*ones(self._x.shape, Float)

self._xsorted = self._is_sorted(self._x)

The important change is the addition of the first two lines, which
delete the cached instances of the clipped data.

Thanks for the bug report!
John Hunter

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by John Hunter | last post: by
3 posts views Thread by John Hunter | last post: by
2 posts views Thread by Grant Edwards | last post: by
reply views Thread by spross | last post: by
reply views Thread by Soren | last post: by
4 posts views Thread by Bill Jackson | last post: by
4 posts views Thread by John Henry | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.