[Python] Matplotlib animation doesn't clear previous frame before plotting new one

Discussão em 'Python' iniciado por Stack, Abril 4, 2025.

  1. Stack

    Stack Membro Participativo

    So, I'm trying to create an animated plot, but I want the previous frame to be cleared before a new one appears. What I keep getting is all frames at the same time or just a blank plot.

    [​IMG]

    fig, ax = plt.subplots()

    campo = ax.plot(x2[0], phiSol[0])[0]

    def init():
    campo.set_data([],[])
    return campo

    def update(frame):
    campo.set_xdata(x2[:frame])
    campo.set_ydata(phiSol[:frame])

    return campo

    anima = ani.FuncAnimation(fig=fig, func=update, init_func=init, frames=40, interval=30)
    HTML(anima.to_jshtml())


    I tried to build an init_func, but none of my tries worked. The last try is that one in the above code. How could I do it?

    Continue reading...

Compartilhe esta Página