-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
60 lines (44 loc) · 1.83 KB
/
utils.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import matplotlib.pyplot as plt
import pandas as pd
import matplotlib.ticker as mticker
def plot_history(point_history, **kwargs):
lower_limit = 0
upper_limit = len(point_history)
window_size = (upper_limit * 10) // 100
plot_rolling_mean_only = False
plot_data_only = False
if kwargs:
if "window_size" in kwargs:
window_size = kwargs["window_size"]
if "lower_limit" in kwargs:
lower_limit = kwargs["lower_limit"]
if "upper_limit" in kwargs:
upper_limit = kwargs["upper_limit"]
if "plot_rolling_mean_only" in kwargs:
plot_rolling_mean_only = kwargs["plot_rolling_mean_only"]
if "plot_data_only" in kwargs:
plot_data_only = kwargs["plot_data_only"]
points = point_history[lower_limit:upper_limit]
# Generate x-axis for plotting.
episode_num = [x for x in range(lower_limit, upper_limit)]
# Use Pandas to calculate the rolling mean (moving average).
rolling_mean = pd.DataFrame(points).rolling(window_size).mean()
plt.figure(figsize=(10, 7), facecolor="white")
if plot_data_only:
plt.plot(episode_num, points, linewidth=1, color="cyan")
elif plot_rolling_mean_only:
plt.plot(episode_num, rolling_mean, linewidth=2, color="magenta")
else:
plt.plot(episode_num, points, linewidth=1, color="cyan")
plt.plot(episode_num, rolling_mean, linewidth=2, color="magenta")
text_color = "black"
ax = plt.gca()
ax.set_facecolor("black")
plt.grid()
plt.xlabel("Episode", color=text_color, fontsize=30)
plt.ylabel("Total Points", color=text_color, fontsize=30)
yNumFmt = mticker.StrMethodFormatter("{x:,}")
ax.yaxis.set_major_formatter(yNumFmt)
ax.tick_params(axis="x", colors=text_color)
ax.tick_params(axis="y", colors=text_color)
plt.show()