-
Notifications
You must be signed in to change notification settings - Fork 0
/
gym_to_gif.py
35 lines (28 loc) · 935 Bytes
/
gym_to_gif.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
from matplotlib import animation
import matplotlib.pyplot as plt
import gym
import sys
import numpy as np
"""
Ensure you have imagemagick installed with
sudo apt-get install imagemagick
Open file in CLI with:
xgd-open <filelname>
"""
def save_frames_as_gif(frames, path='./', filename='gym_animation.gif'):
#Mess with this to change frame size
plt.figure(figsize=(frames[0].shape[1] / 72.0, frames[0].shape[0] / 72.0), dpi=72)
patch = plt.imshow(frames[0])
plt.axis('off')
def animate(i):
patch.set_data(frames[i])
anim = animation.FuncAnimation(plt.gcf(), animate, frames = len(frames), interval=50)
anim.save(path + filename, writer='imagemagick', fps=60)
def main():
filename = sys.argv[1]
gif_filename = sys.argv[2]
frames = np.load(filename)
print(frames.shape)
save_frames_as_gif(frames, path="results/", filename=gif_filename)
if __name__ == '__main__':
main()