-
Notifications
You must be signed in to change notification settings - Fork 5
/
visualization.py
32 lines (25 loc) · 1001 Bytes
/
visualization.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
import matplotlib.pyplot as plt
import os
class Visualization:
def __init__(self, path, dpi):
self._path = path
self._dpi = dpi
def save_data_and_plot(self, data, filename, xlabel, ylabel):
"""
Produce a plot of performance of the agent over the session and save the relative data to txt
"""
min_val = min(data)
max_val = max(data)
plt.rcParams.update({'font.size': 24}) # set bigger font size
plt.plot(data)
plt.ylabel(ylabel)
plt.xlabel(xlabel)
plt.margins(0)
plt.ylim(min_val - 0.05 * abs(min_val), max_val + 0.05 * abs(max_val))
fig = plt.gcf()
fig.set_size_inches(20, 11.25)
fig.show()
fig.savefig(os.path.join(self._path, 'plot_'+filename+'.png'), dpi=self._dpi)
with open(os.path.join(self._path, 'plot_'+filename + '_data.txt'), "w") as file:
for value in data:
file.write("%s\n" % value)