forked from Rintarooo/VRP_DRL_MHA
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmakegif.py
32 lines (28 loc) · 1.08 KB
/
makegif.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
# https://own-search-and-study.xyz/2017/05/18/python%E3%81%AEmatplotlib%E3%81%A7gif%E3%82%A2%E3%83%8B%E3%83%A1%E3%82%92%E4%BD%9C%E6%88%90%E3%81%99%E3%82%8B/
from glob import glob
import os
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
if __name__ == "__main__":
folderName = "../../Downloads"
if not os.path.isdir(folderName):
raise FileNotFoundError("check folderName")
picList = glob(folderName + "/newplot*.png")
picList = sorted(picList)
print(picList)
fig = plt.figure(figsize = (8.0, 7.0))
ax = plt.subplot(111)
ax.axis("off")
fig.tight_layout()
ims = []
#画像ファイルを順々に読み込んでいく
for i in range(len(picList)):
#1枚1枚のグラフを描き、appendしていく
tmp = Image.open(picList[i])
#エイリアシングを防ぐため、線形補完
ims.append([plt.imshow(tmp, interpolation="spline36")])
#アニメーション作成
ani = animation.ArtistAnimation(fig, ims, interval = 150, repeat_delay = 1000)
ani.save("./test.gif", writer = "imagemagick")