0

I'm trying to make an animation with beads moving along predefined paths. I calculated the trajectories as lists with x and y coordinates with certain starting points. I'm trying to make an animation with the simultaneous movement of beads along all trajectories. But only the last one is animated. I suspect that this is due to the incorrect construction of the animation loop.

    # In this block, I count the coordinates using third-party functions u_f and u_b
init_y= np.linspace(channel_width/20, channel_width-no_slip*5,10) #numbers of trajectory
fig, ax = plt.subplots() #fig initialization
x_list = [] #List of x lists for each trajectory
y_list = [] # of y
for j in range(len(init_y)): #Direct calculation of coordinates. We take starting points with x = 0 and different y's
    coord_x1 = []             # and use the speed functions.
    coord_y1 = []
    coord_x1.append(0)
    coord_y1.append(init_y[j])
    for i in range(1, 10000):
        coord_x1.append(coord_x1[i-1] + dt * u_f(coord_y1[i-1], Q, channel_width, channel_length))
        coord_y1.append(coord_y1[i-1] + dt * u_m(coord_y1[i-1], coord_x1[i-1], 1, *popt1, *popt))

        if coord_x1[i] >= channel_length:
            break
        elif coord_y1[i] >= channel_width:
            break
        elif coord_y1[i] <= 0:
            break
        else:
            continue
    x_list.append(coord_x1)
    y_list.append(coord_y1)
    
#Animation block.
def animate(i):
    redDot.set_data(x_list[j][i], y_list[j][i])
    return redDot,

for j in range(len(init_y)):
    plt.plot(x_list[j], y_list[j])
    ax = plt.axis([0, channel_length, 0, channel_height])
    redDot, = plt.plot(x_list[j][0], y_list[j][0], 'ro')
    #for i in range(len(x_list[j])):
myAnimation = animation.FuncAnimation(fig, animate, frames=135, interval=10, blit=True, repeat=True)
plt.show()

enter image description here

Maker
  • 25
  • 5
  • 1
    Does this answer your question? [Animate grouped scatter points in matplotlib](https://stackoverflow.com/questions/76566196/animate-grouped-scatter-points-in-matplotlib) – jared Jun 30 '23 at 15:02
  • Yes, that's what I need. Thank you very much. – Maker Jul 03 '23 at 06:55

0 Answers0