[我在这里尝试显示下巴的动画。运行代码会在调用OnClicked()事件时出现错误。
def OnClicked(self, e):
print("ok")
self.ani = animation.FuncAnimation(self.figure_animation, self.animate , init_func=self.init, interval=0.1,
blit=True)
def init(self): # only required for blitting to give a clean slate.
x = self.mat_px[0]
y = self.mat_py[0]
self.jaw_outline.set_data(x, y)
return self.img, self.jaw_outline
def animate(self, i):
# update the data
x = self.mat_px[i]
y = self.mat_py[i]
self.jaw_outline.set_data(x, y)
poa = self.axes_animation.scatter(self.h2_POA_pos[i], self.K2_POA_pos[i], color='red', s=150)
jaw_area_fill = self.axes_animation.fill_between(x, y, 0, facecolor=[(254 / 255, 157 / 255, 111 / 255)])
return self.img, self.jaw_outline, jaw_area_fill, poa
考虑一下,如果self.mat_px的长度为80,那么我在pycharm控制台中连续出现此“索引80超出轴80尺寸80的范围”的错误。我收到如下所示的不间断错误。
并且如果我将blit设置为False,那么我不会收到任何错误,但这样做不会给我正确的结果。请帮助我解决此问题。
我建议使用%
(模)运算符(请参见Binary arithmetic operations),以将索引分别限制在self.mat_px
的范围内self.mat_py
:
x = self.mat_px[i % len(self.mat_px)]
y = self.mat_py[i % len(self.mat_py)]