-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimate_png.py
37 lines (31 loc) · 1.23 KB
/
animate_png.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os
import sys
import matplotlib.pyplot as plt
import matplotlib.animation as animation
# read the png files
dir1 = os.listdir("PNG")
if len(dir1) != 0:
imgs = ["PNG/arrow"+ str(i) + ".png" for i in range(1, 99)]
frames = []
fig = plt.figure()
for i in imgs:
new_frame = plt.imread(i)
frames.append([plt.imshow(new_frame, animated=True)])
# create animation using the png files
ani = animation.ArtistAnimation(fig, frames, interval=100, blit=True, repeat=False)
plt.show()
# save the animation as a mp4. This requires ffmpeg to be installed
ani.save('animations/animationClustering_learning.mp4', writer='ffmpeg', fps=10)
dir2 = os.listdir("PNG2")
if len(dir2) != 0:
imgs = ["PNG2/arrow"+ str(i) + ".png" for i in range(1, 99)]
frames = []
fig = plt.figure()
for i in imgs:
new_frame = plt.imread(i)
frames.append([plt.imshow(new_frame, animated=True)])
# create animation using the png files
ani = animation.ArtistAnimation(fig, frames, interval=100, blit=True, repeat=False)
plt.show()
# save the animation as a mp4. This requires ffmpeg to be installed
ani.save('animations/animationClustering_geometry.mp4', writer='ffmpeg', fps=10)