python animation ... passing an argument -
i have simple python animation program downloaded. changing around understand animation calls little better. program makes simple dot move in circle on screen. placed functions change dot's position , animation calls each class. worked ok. put definition of figure class. works ok too. how looks,
import numpy np import matplotlib.pyplot plt import matplotlib.animation animation class fig: def __init__(self): self.fig=plt.figure() self.ax = self.fig.add_subplot(111) self.line, = self.ax.plot([], [], 'bo', ms=10) self.ax.set_ylim(-1, 1) self.ax.set_xlim(-1, 1) class sd: def simdata(self): t_max = 100.0 dt = 0.001 x = 0.0 t = 0.0 while t < t_max: x = np.sin(np.pi*t) t = t + dt y = np.cos(np.pi*t) yield x, y class sp: def simpoints(self,simdata): x, t = simdata[0], simdata[1] f1.line.set_data(t, x) return f1.line #line2#, time_text f1=fig() sd=sd() sp=sp() ani = animation.funcanimation(f1.fig, sp.simpoints, sd.simdata, blit=false, interval=10, repeat=true) plt.show()
now, want pass figure instace argument through animation call. not work, new code not work....
import numpy np import matplotlib.pyplot plt import matplotlib.animation animation class fig: def __init__(self): self.fig=plt.figure() self.ax = self.fig.add_subplot(111) self.line, = self.ax.plot([], [], 'bo', ms=10) self.ax.set_ylim(-1, 1) self.ax.set_xlim(-1, 1) class sd: def simdata(self): t_max = 100.0 dt = 0.001 x = 0.0 t = 0.0 while t < t_max: x = np.sin(np.pi*t) t = t + dt y = np.cos(np.pi*t) yield x, y class sp: def simpoints(self,simdata,figg): x, t = simdata[0], simdata[1] figg.line.set_data(t, x) return figg.line #line2#, time_text f1=fig() sd=sd() sp=sp() ani = animation.funcanimation(f1.fig, sp.simpoints, sd.simdata, f1, blit=false, interval=10, repeat=true) plt.show()
the compiler tells me,
self._drawn_artists = self._init_func() attributeerror: fig instance has no __call__ method
any comments appreciated. thanks
Comments
Post a Comment