I have the following animation code:
# 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()
However, when I uncomment the ax.set_ylim(0, np.max(psi_vals[frame]))
line to try to implement a dynamical resizing of the y-axis, it stays frozen on the first frame. I have tried setting blit=False
and uncommenting as well, but that also keeps it frozen on the first line. I believe the updating is correct, as it does show the animation with a non-dynamic y-axis when the line is kept commented.
1