Search code examples
pythonpandasmatplotlibseabornmatplotlib-animation

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)

Solution

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