我是Python的初学者。我正在尝试制作一个点在水平方向移动的动画。但是,当我运行代码时,我收到了以下错误:
TypeError: 'PathCollection' object is not iterable
我不知道该如何修复它。
#----------------------------------------------------------------------
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
Acc_11 = [1,2,3,4,6,7]
lenAcc11 = len(Acc_11)
Acc_12 = [2,2,2,2,2,2]
# Scatter plot
fig = plt.figure(figsize = (5,5))
ax = plt.axes()
scat = ax.scatter([],[])
#initial func
def init():
return scat
#animation func
def ani (i):
for i in range(0,lenAcc11):
acc_11 = Acc_11[i]
print (acc_11)
acc_11_pos = Acc_12[i]
print (acc_11_pos)
scat = scat.set_data(acc_11,acc_11_pos)
return scat
ani = FuncAnimation(fig, ani, init_func = init, interval = 10, blit =True)
plt.show()
#--------------------------------------------------------------------------
set_data
方法,请尝试使用set_array
。 - hashmuke