I would like to create an animation of the function f(x,t)=cos(kx-wt) where x would be an array # from 0 to 2*pi, k any constant, w any other constant and each frame would be a value of t different from, say, 0 to 10.
I'm starting to learn about python and the matplotlib library now, I looked in the documentation but I can't understand or I couldn't find a similar problem.
One way I thought of doing it was:
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(5,2))
T = np.linspace(0,10,100)
K = 3.
w = 1.
x = np.linspace(0, 2\*np.pi, 100)
for t in T:
cos = np.cos(K*x - w*t)
ax.plot(x, cos)
plt.pause(0.001)
plt.show()
but the axes are printed one after the other, and not quite what I imagined. I would like each curve of this separated in a frame and not all together.