Multi body animation in python returns static picture
Question: Here is a program that I have written to do an animation in `matplotlib`. The
program concerns a system of 18 particles arranged initially in a hexagonal
lattice. The initial configuration is given under the definition of
`simPoints(simData)`.

The system is evolved over time according to the rule `x[i]=x[i]+L/2.0`, in
both x and y direction. Particles going out of the window are brought in
through the other side. These updates are mentioned under the function
`simData()`.

But all I get out of this code is a static picture of the initial
configuration of particles.

    
    
    from numpy import*
    import matplotlib.pyplot as plt
    import matplotlib.animation as animation
    
    L=1         # lattice constant = sigma*2**0.5 (Let)
    
    x=zeros(18,float)
    y=zeros(18,float)
    
    
    #~~~~~~~~~~~~~~~~~ ANIMATION ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    def simData():
        t = 1
        while t<=20:
            for i in range(18):
                x[i]=x[i]+L/2.0
                y[i]=y[i]+L/2.0
                if x[i]>L*3:                    # translate back the particle if it goes out of window limit 0 to L*cell
                    x[i]=x[i]-L*3
                elif x[i]<0:
                    x[i]=L*3-x[i]
                if y[i]>L*3:                    # translate back the particle if it goes out of window limit 0 to L*cell
                    y[i]=y[i]-L*3
                elif y[i]<0:
                    y[i]=L*3-y[i]
            t=t+1
        yield x, y
    
    def simPoints(simData):
        k=0
        for i in range(0,6,1):
            for j in range(0,6,1):
                if (i+j)%2==0:
                    x[k]=i*L*.5+.25*L
                    y[k]=j*L*.5+.25*L
                    k=k+1
        line.set_data(x, y)
        return line,
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    
    line, = ax.plot(x, y,'bo', ms=8)
    ax.set_ylim(0, L*3)
    ax.set_xlim(0, L*3)
    ani = animation.FuncAnimation(fig, simPoints, simData, blit=False, interval=100)
    
    plt.show()
    

How can I animate the lattice? I have a feeling that the argument
`interval=100` is not used wisely.


Answer: I've made some minor changes in Your code, as You can see below. It's
animating now, however the `simPoints()` is commented out. The major issue is
that if You initialize the points like that, after each step they end up in
the same places. Dots move, but another dots take their places, so it looks
like the plot isn't moving. You may want to change the `simData()` function,
for example make the changes more subtle or random, to avoid that case.

    
    
    from numpy import*
    import matplotlib.pyplot as plt
    import matplotlib.animation as animation
    
    L=1         # lattice constant = sigma*2**0.5 (Let)
    
    x=array([0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,0.1,0.11,0.12,0.13,0.14,0.15,0.16,0.17,0.18])
    #x=zeros(18,float)
    y=zeros(18,float)
    
    #~~~~~~~~~~~~~~~~~ ANIMATION ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    def simData():
        t = 1
        while t<=20:
            for i in range(18):
                x[i]=x[i]+L/2.0
                y[i]=y[i]+L/2.0
                if x[i]>L*3:                    # translate back the particle if it goes out of window limit 0 to L*cell
                    x[i]=x[i]-L*3
                elif x[i]<0:
                    x[i]=L*3-x[i]
                if y[i]>L*3:                    # translate back the particle if it goes out of window limit 0 to L*cell
                    y[i]=y[i]-L*3
                elif y[i]<0:
                    y[i]=L*3-y[i]
            t=t+1
    
    def simPoints():
        k=0
        for i in range(0,6,1):
            for j in range(0,6,1):
                if (i+j)%2==0:
                    x[k]=i*L*.5+.25*L
                    y[k]=j*L*.5+.25*L
                    k=k+1
    
    fig = plt.figure()
    ax = plt.axes()
    #simPoints()
    line, = ax.plot(x, y,'bo', ms=8)
    ax.set_ylim(0, L*3)
    ax.set_xlim(0, L*3)
    
    def animate(i):
        simData()
        print x
        line.set_data(x, y)
        return line,
    
    ani = animation.FuncAnimation(fig, animate, blit=False, interval=100, frames=200)
    
    plt.show()
    

