我有一个简单的python动画程序,我下载了。我正在改变它以更好地理解动画调用。该程序在屏幕上以圆圈形式进行简单的点移动。我放置了改变点位置和动画调用的函数。那没关系。然后我把图的定义放到一个类中。这也行得通。这是它的外观,
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as 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()
现在,我想通过动画调用将图形实例作为参数传递。但它不起作用,这是新的代码不起作用....
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as 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()
编译器告诉我,
self._drawn_artists = self._init_func()
AttributeError: FIG instance has no __call__ method
任何评论都表示赞赏。 感谢