Skip to content Skip to sidebar Skip to footer

Runtimeerror: The Init_func Must Return A Sequence Of Artist Objects

I am trying to test a Matplotlib animation example on my jupyter notebook which is listed as following: from matplotlib import animation # solve the ode problem of the double comp

Solution 1:

As the error suggests, and as can be seen e.g. in the simple_animation example, but also from the FuncAnimation documentation, the init_func as well as the updating func are supposed to return an iterable of artists to animate.

The documentation does not say that this is actually only needed when using blit=True, but since you are using blitting here, it is definitely needed.

What you would therefore need to do is to let the init function as well as the update function return the two lines which get animated

def init():
    pendulum1.set_data([], [])
    pendulum2.set_data([], [])
    return pendulum1, pendulum2, 

def update(n): 
    # n = frame counter# calculate the positions of the pendulums
    x1 = + L * sin(x[n, 0])
    y1 = - L * cos(x[n, 0])
    x2 = x1 + L * sin(x[n, 1])
    y2 = y1 - L * cos(x[n, 1])

    # update the line data
    pendulum1.set_data([0 ,x1], [0 ,y1])
    pendulum2.set_data([x1,x2], [y1,y2])

    return pendulum1, pendulum2, 

Post a Comment for "Runtimeerror: The Init_func Must Return A Sequence Of Artist Objects"