I'm writing a short script in Python that is supposed to graph a series of scatter Cartesian points, one at a time as an animation (i.e., one frame is a point, the next frame is another). I'm using matplotlib.
My program currently plots correctly, but it returns a static plot with all the points on the plot, so something must be wrong with the animation function itself.
When I run the code now, despite returning a plot I receive AttributeError: 'PathCollection' object has no attribute 'set_data'. I've tried tweaking several small things, but generally that error message remains the same. Thank you in advance!
import matplotlib
from matplotlib import pyplot as plt
from matplotlib import animation
import numpy as np
pole_list = [(1,2), (2,3), (3,3), (3,2), (3,1), (4,1), (3,1)] #arbitrary list of points
fig, ax = plt.subplots(1,1)
x_val = [x[0] for x in pole_list]
y_val = [x[1] for x in pole_list]
scatterplot = ax.scatter(x_val, y_val)
print(x_val, y_val)
def init():
scatterplot.set_data([], [])
return scatterplot,
def animate(i, x_val, y_val):
scatterplot.set_data(x_val, y_val)
return scatterplot,
animate = animation.FuncAnimation(fig, animate, fargs=(x_val,y_val), init_func=init, frames=8, interval=20, blit = True)
plt.show()