The code is shown below. I am attempting to animate using vectors calculated earlier a figure window is opened so i know it gets this far and the vectors are being calclated correctly. But matplotlib oututs nothing but the figure window I have no idea why. Please help.
#finally animateing
fig = plt.figure()
ax = plt.axes(xlim = (-1000,1000) ,ylim = (-1000,1000))#limits were arbitrary
#line = ax.plot([],[])
line, = ax.plot([], [], lw=2)
# initialization function: plot the background of each frame
def init():
line.set_data([], [])
return line,
def animate(i):
x = time_vec[i]
y = complex_vec[i]
#y1 = real_vec[i]
#y2 = modulus_vec[i]
line.set_data(x,y)
#line.set_data(x,y1)
#line.set_data(x,y2)
return line,
animation_object = animation.FuncAnimation(fig, animate, init_func= init, frames = num_files,interval = 30, blit = True)
#turnn this line on to save as mp4
#anim.save("give it a name.mp4", fps = 30, extra-args = ['vcodec', 'libx264'])
plt.show()
THE FULL ERROR MESSAGE IS SHOWN BELOW
Traceback (most recent call last):
File "the_animation.py", line 71, in <module>
plt.show()
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 145, in show
_show(*args, **kw)
File "/usr/lib/pymodules/python2.7/matplotlib/backend_bases.py", line 117, in __call__
self.mainloop()
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line 69, in mainloop
Tk.mainloop()
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 366, in mainloop
_default_root.tk.mainloop(n)
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1484, in __call__
def __call__(self, *args):
MINIMAL EXAMPLE
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation
complex_vec = np.arange(5,6,.001)
real_vec = np.arange(7,8,.001)
time_vec = np.arange(0,1,.001)
num_files = np.size(time_vec)
#creating the modulus vector
modulus_vec = np.zeros(np.shape(complex_vec))
for k in range (0,complex_vec.size):
a = complex_vec[k]
b = real_vec[k]
calc_modulus = np.sqrt(a**2 + b**2)
modulus_vec[k] = calc_modulus
#finally animateing
fig = plt.figure()
ax = plt.axes(xlim = (-1000,1000) ,ylim = (-1000,1000))#limits were arbitrary
#line = ax.plot([],[])
line, = ax.plot([], [], lw=2)
# initialization function: plot the background of each frame
def init():
line.set_data([], [])
return line,
def animate(i):
x = time_vec[i]
y = complex_vec[i]
y1 = real_vec[i]
y2 = modulus_vec[i]
line.set_data(x,y)
line.set_data(x,y1)
line.set_data(x,y2)
return line,
animation_object = animation.FuncAnimation(fig, animate, init_func= init, frames = num_files,interval = 30, blit = True)
#turnn this line on to save as mp4
#anim.save("give it a name.mp4", fps = 30, extra-args = ['vcodec', 'libx264'])
plt.show()