-
Notifications
You must be signed in to change notification settings - Fork 4
/
graph.py
51 lines (40 loc) · 1.17 KB
/
graph.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
import matplotlib.pyplot as plt
import numpy as np
import re
import sys
BACKGROUND = "#404040"
EVALUATION = "#fb8b24"
WIDTH_PER_PLY = 0.2
try:
file_path = sys.argv[1]
except IndexError:
file_path = "analysis.ptn"
with open(file_path, "r", encoding="utf-8") as file:
evals = np.array(
[
float(match)
for match in re.findall("{evaluation: ([+-]\d.\d*)}", file.read())
]
)
plies = evals.size
# plotting
fig = plt.figure(figsize=(WIDTH_PER_PLY * plies, 5), tight_layout=True, dpi=200)
ax = plt.axes()
ax.set_facecolor(BACKGROUND)
less = evals < 0
black = less | np.roll(less, 1)
white = ~less | np.roll(~less, 1)
b_evals = evals.clip(max=0)
w_evals = evals.clip(min=0)
x = 1 + np.arange(plies) / 2
ax.plot(x, np.zeros(plies), color="gray")
ax.plot(x, evals, drawstyle="steps-post", color=EVALUATION)
ax.fill_between(x, b_evals, step="post", where=black, color="black")
ax.fill_between(x, w_evals, step="post", where=white, color="white")
ax.set_title("Evaluation Graph")
ax.set_xlabel("Move Number")
ax.set_ylabel("Evaluation")
ax.set_xbound(1, (plies + 1) / 2)
ax.set_ybound(-1, 1)
ax.set_xticks(x[::2])
plt.savefig("graph.png")