I have code that generates graphs of a propagating gausian. Each plot plt.plot(r, Sevol[0]) generates an image of the type:
Many subplots at the same figure generetes the image above:
plt.plot(r, Sevol[0])
plt.plot(r, Sevol[10])
plt.plot(r, Sevol[20])
plt.plot(r, Sevol[30])
plt.plot(r, Sevol[40])
I want to make an animation where I can plot each image generated by one plt.plot(r, Sevol[i]) at a time, so that the previous one is superimposed by the next one.
fig = plt.figure()
plt.xlabel('r')
plt.xlabel('S')
plt.grid()
#plt.plot(r, Sevol[0])
#plt.plot(r, Sevol[2])
#plt.plot(r, Sevol[3])
#plt.plot(r, Sevol[4], color='C1', linestyle='--', linewidth=1)
#plt.plot(r, Sevol[5], color='C0', linestyle='--', linewidth=1)
#plt.plot(r, Sevol[6], color='C1', linestyle='--', linewidth=1)
plt.xlim(ri, rf)
graph, = plt.plot([], [], color='gold', markersize=3)
def animate(i):
graph.set_data(r[:i], Sevol[:i])
return graph,
skipframes = int(len(r)/200)
if skipframes == 0:
skipframes = 1
ani = FuncAnimation(fig, animate, frames=range(0,len(r),skipframes), interval=10, blit = True, repeat = False)
ani

