Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib funcAnimation isn't calling the passed function

I'm trying to animate the links of a robot without success. FuncAnimation never calls the animate function -- the print statement is never executed. Any help would be greatly appreciated. My code:

def foo():
    joints = np.array([robot_kinematics.getJoints(a[0]) for a in path])
    # this is [5x9x3]
    
    fig    = plt.figure()
    ax     = fig.add_subplot(111, projection='3d')
    colors = 'brgymcwkk'
    lines  = [ax.plot([], [], [])[0] for i,c in enumerate(colors)]
    pt     = ax.plot([], [], [])[0] 
 
    
    def animate(i,lines,pts):
       print ('called')
       for j,line in enumerate(lines):
           line.set_data(joints[i,j,0:2])
           line.set_3d_properties(joints[i,j,2])
       pts.set_data(joints[i,:,0:2])
       pts.set_3d_properties(joints[i,:,2])
           
       return lines,pts
       
    a = animation.FuncAnimation(fig, animate, 25, fargs=(lines,pt),interval=50, blit=False)    
    plt.show()

foo()
like image 222
JoshuaF Avatar asked Jan 13 '17 00:01

JoshuaF


1 Answers

The object created by FuncAnimation must be assigned to a global variable apparently; if it's assigned to a local variable, as I did here, nothing will happen.

like image 144
JoshuaF Avatar answered Oct 21 '22 11:10

JoshuaF