Skip to content
Advertisement

How do I animate this graph to just display the next row

enter image description here

So I tried this, I’m working in a jupyter notebook and am wondering how to animate the next row of data.

enter code here 
def animate(i):
    data = df.iloc[i]
    return data
ani = matplotlib.animation.FuncAnimation(fig, animate, frames=53, interval=700, repeat=True)

Advertisement

Answer

For what I can see in the documentation you have to set the plot data inside the animate function. You must also have an instance to your plot and use that same instance inside the animate function.

fig, ax = plt.subplots()
p, = plt.plot(df.columns, df.iloc[0])

def animate(i):
    print(df.iloc[i])
    p.set_data(df.columns, df.iloc[i])
    return p


ani = matplotlib.animation.FuncAnimation(fig, animate, frames=20, interval=10, blit=True, repeat=True)
plt.show()
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement