I have 425 files, Ex1, Ex2, Ex3,...,Ex425. Each file correspond to one time-step. Each file contains one column of electric field amplitudes. So at time t=1, Ex1 is the field in space of 200 points, and so on. I want to make an one dimensional animation of these files in python but couldn't achieve it. Can anyone help?
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation
basename = "Ex"
numFiles = 425
fig = plt.figure()
ax = plt.axes(xlim=(0, 200), ylim=(-2, 2))
line, = ax.plot([], [], lw=2)
def init():
line.set_data([], [])
return line,
def animate(i):
x = np.linspace(0, 200, 1)
for t in range(1,numFiles):
filename = basename + str(t)
data = np.loadtxt(filename)
line.set_data(x, data[:,0])
return line,
anim = animation.FuncAnimation(fig, animate,
init_func=init,frames=200, interval=20, blit=True)
plt.show()