enter code here
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig = plt.figure()
ax = plt.axes(xlim=(0, 1), ylim=(-.25, .2))
filename = '{}{}'.format("file_1",".txt")
data1=np.loadtxt(filename)
filename = '{}{}'.format("file_2",".txt")
data2=np.loadtxt(filename)
colors1 = ['b', 'b', ]
colors = ['r', 'r']
lines = sum([ax.plot([], [], [], '-', c=c)
for c in colors], [])
pts = sum([ax.plot([], [], [], 'o', c=c)
for c in colors], [])
lines1 = sum([ax.plot([], [], [], '-', c=c)
for c in colors1], [])
pts1 = sum([ax.plot([], [], [], 'o', c=c)
for c in colors1], [])
def init():
for line, pt, line1, pt1 in zip(lines, pts, lines1, pts1):
line.set_data([], [])
pt.set_data([], [])
line1.set_data([], [])
pt1.set_data([], [])
return lines + pts + lines1 + pts1
def animate(i):
for line, pt, line1, pt1, xi, yi in zip(lines, pts, lines1, pts1, data1, data2):
x, y = data1[:i].T
p, q = data2[:i].T
line.set_data(x, y)
pt.set_data(x[-1:], y[-1:])
line1.set_data(p, q)
pt1.set_data(p[-1:], q[-1:])
return lines + pts + lines1 + pts1
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=7000, interval=10, blit=True)
Writer = animation.writers['ffmpeg']
writer = Writer(fps=500, metadata=dict(artist='Me'), bitrate=100)
anim.save('video.mp4', writer=writer)
plt.show()