Код: Выделить всё
# Update function for animation
def update(frame):
line.set_ydata(psi_vals[frame]) # Update the y-data for each time step
# ax.set_ylim(0, np.max(psi_vals[frame]))
ax.set_title(f'Time: {t_vals[frame]:.2f}') # Update the title to show the current time
return line,
from matplotlib.animation import FuncAnimation
# Create the animation
ani = FuncAnimation(fig, update, frames=len(t_vals), interval=100, blit=True, repeat=False)
# Display the animation
plt.show()
Подробнее здесь: https://stackoverflow.com/questions/790 ... -animation