我对python真的很陌生,刚刚开始使用类。 我正在用Python构建一个移动球,但我遇到了以下错误:
TypeError Traceback (most recent call last)
<ipython-input-1-7cff16ca52e8> in <module>
33 matplotlib.pyplot.plot(pos,5,'bo', markersize=5)
34
---> 35 animator=matplotlib.animation.FuncAnimation()
TypeError: __init__() missing 2 required positional arguments: 'fig' and 'func'
这是我的代码:
%pylab inline
time = 0
class Ball:
def __init__(self,xvelocity=1, yvelocity=1, inx=1,iny=5, posx=[],posy=[]):
self.xvelocity=xvelocity
self.yvelocity=yvelocity
#giving velocity
self.inx=inx
self.iny=iny
#defining starting position
self.posx = [self.inx]
self.posy = [self.iny]
ball=Ball()
x=[0, 10]
y=[0, 10]
pos=int(ball.xvelocity)*int(time)
matplotlib.pyplot.plot(x,y, 'ro', markersize=0.0001)
for time in range(15):
posx=int(ball.xvelocity)*int(time)
if pos!=10:
pos=pos%10
matplotlib.pyplot.plot(pos,5,'bo', markersize=5)
animator=matplotlib.animation.FuncAnimation()
在这些情况下,最好的方法是检查documentation。我们在函数签名中看到:
这表明它需要两个必需的参数,
fig
和func
按顺序,然后是可选参数列表。在代码中不传递任何参数:因此,需要对其进行更新,以包含这些参数。上面的文档应该能让您很好地了解哪些类型的对象是有效的。例如,我们看到} 类型的对象。在您的代码中,您还没有声明这样一个对象,所以您必须构造一个
fig
应该是^{相关问题 更多 >
编程相关推荐