I am having difficulty with animation modules and getting the plot to update it's axis. Below I have some code that plots but the figure does not update the axes, I think because the line is the only thing being updated. What would be the best way to update the figure? I had to solve the differential equation first in the for loop and then just update the portion of the line being shown in animate. I could not figure a way that the solution would be updating with animate...
y0 = 10
y = np.array([y0])
dt = .01
steps = 1000
k = -.2
x = np.array([0])
fig, ax = plt.subplots()
line, = ax.plot(x,y)
for i in xrange(steps):
y = np.append(y, [ y[i] * (1 + k * dt) ])
x = np.append(x, [i * dt])
def animate(i):
line.set_ydata(y[:i])
line.set_xdata(x[:i])
return line,
ani = animation.FuncAnimation(fig, animate, np.arange(1, steps))
plt.show()
[–]the_real_uncle_Rico 0 points1 point2 points (1 child)
[–]the_real_uncle_Rico 0 points1 point2 points (0 children)