-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_animation.py
35 lines (24 loc) · 751 Bytes
/
make_animation.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.animation import FuncAnimation
from matplotlib import animation
import matplotlib.pyplot as plt
import matplotlib
import numpy as np
import pickle
matplotlib.use('TkAgg')
with open('int_reward', 'rb') as f:
pkl = pickle.load(f)
fig, ax = plt.subplots()
xdata, ydata = [], []
line, = ax.plot([], [], lw=2)
def init():
ax.set_xlim(0, len(pkl) + 5)
ax.set_ylim(pkl.min(), 1)
return line,
def update(frame):
xdata.append(int(frame) - 1)
ydata.append(pkl[int(frame) - 1, 0])
line.set_data(xdata, ydata)
return line,
ani = FuncAnimation(fig, update, frames=np.linspace(0, len(pkl) - 1, len(pkl), endpoint=False),
init_func=init, blit=True, interval=20, repeat=False)
plt.show()