I am trying to animate the path of a projectile launched with an initial velocity at an initial angle. I attempted to modify the code found here: http://matplotlib.org/examples/animation/simple_anim.html
My code looks like this:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig, ax = plt.subplots()
g = 9.8 #value of gravity
v = 20 #initial velocity
theta = 20*np.pi/180 #initial angle of launch in radians
tt = 2*v*np.sin(theta)/g #total time of flight
t = np.linspace(0, tt, 0.01) #time of flight into an array
x = v*np.cos(theta)*t #x position as function of time
line, = ax.plot(x, v*np.sin(theta)*t-(0.5)*g*t**2) #plot of x and y in time
def animate(i):
line.set_xdata(v*np.cos(theta)*(t+i/10.0))
line.set_ydata(v*np.sin(theta)*(t+i/10.0)-(0.5)*g*(t+i/10.0)**2)
return line,
#Init only required for blitting to give a clean slate.
def init():
line.set_xdata(np.ma.array(t, mask=True))
line.set_ydata(np.ma.array(t, mask=True))
return line,
ani = animation.FuncAnimation(fig, animate, np.arange(1, 200),
init_func=init, interval=25, blit=True)
plt.show()
The code, as shown, gives me plot window, but no trajectory and no animation. I've searched on here to see if this has been asked elsewhere, and I have yet to find it. If it has been asked, just link to the already answered question. Any help is greatly appreciated. Thanks all.