Home>

I am creating an animation using FuncAnimation ().
I'm drawing using set_data () in the function that FuncAnimation () calls every time. Can you ask Professor Kago?
Thanking you in advance.

  • Answer # 1

    Is it like this

    import matplotlib.animation as anm
    import matplotlib.pyplot as plt
    import matplotlib.cm as cm
    import numpy as np
    fig = plt.figure ()
    def update (i):
        if i! = 0:
            plt.cla ()
        z = np.sin (i * 2 * np.pi/100)
        plt.scatter (0, 0, c = z, vmin = -1, vmax = 1, cmap = cm.bwr)
    ani = anm.FuncAnimation (fig, update, frames = 100, interval = 50)
    plt.show ()

    [Added]

    Example usingset_color ()

    import matplotlib.animation as anm
    import matplotlib.pyplot as plt
    import matplotlib.cm as cm
    import numpy as np
    fig = plt.figure ()
    ax = fig.add_subplot (1,1,1)
    line, = ax.plot ([], [])
    ax.set_ylim (-1, 1)
    def update (i, ax, line):
        x = np.arange (i)
        y = np.sin (x * 2 * np.pi/100)
        line.set_data (x, y)
        line.set_color (cm.bwr (plt.Normalize (vmin = 0, vmax = 100) (i)))
        ax.set_xlim (0, i)
    ani = anm.FuncAnimation (fig, update, fargs = (ax, line), frames = 100, interval = 50)
    plt.show ()

Related articles