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

Time:03-20

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)

CodePudding user response:

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()
  • Related