import matplotlib.pyplot as plt
import numpy as np
import cv2
from matplotlib import animation
img0 = np.zeros((200, 400, 3), dtype=np.uint8)
fig = plt.figure()
ax = plt.gca()
line = plt.imshow(img0)
def animate(i):
img = cv2.rectangle(img0.copy(), (167+4i, 100), (187+4i, 120), (255, 255, 255))
speed=0.161
img = cv2.rectangle(img, (143 + 4 * i, 100), (163 + 4 * i, 120), (255, 255, 255))
img = cv2.rectangle(img, (118 + 4 * i, 100), (138 + 4 * i, 120), (255, 255, 255))
img = cv2.rectangle(img, (92 + 4 * i, 100), (112 + 4 * i, 120), (255, 255, 255))
img = cv2.rectangle(img, (65 + 4 * i, 100), (85 + 4 * i, 120), (255, 255, 255))
img = cv2.rectangle(img, (39 + 4 * i, 100), (59 + 4 * i, 120), (255, 255, 255))
img = cv2.rectangle(img, (10 + 4 * i, 100), (30 + 4 * i, 120), (255, 255, 255))
line.set_data(img)
return line
anim = animation.FuncAnimation(fig, animate, frames=50, interval=200, repeat=False)
plt.show()