I am a beginner to Python. I'm trying to make an animation of a point moving in the horizontal direction. But, when I ran the code I received the below error:
TypeError: 'PathCollection' object is not iterable
I have no idea how to fix it.
#----------------------------------------------------------------------
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()
#--------------------------------------------------------------------------