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
|
from src.logger import LOG
def create_string_array(values):
return f"[{','.join(str(x) for x in values)}]"
def create_distribution_script(*, values, title, save_path):
values_string = create_string_array(values)
output = f'''
import numpy as np
import matplotlib.pyplot as plt
a = np.hstack({values_string})
plt.hist(a, bins='auto') # arguments are passed to np.histogram
plt.title("{title}")
plt.show()'''
fh = open(save_path, 'w')
fh.write(output)
fh.close()
LOG.info(f'Run: {save_path}, to look at {title} distribution.')
def create_plots(*, plots, xlabel, ylabel, save_path):
legends = "["
xlist = "["
ylist = "["
for plot in plots:
legends += "'" + plot['legend'] + "'" + ','
xlist += create_string_array(plot['points_x']) + ','
ylist += create_string_array(plot['points_y']) + ','
legends += ']'
xlist += ']'
ylist += ']'
output = f'''
import pylab
legends = {legends}
xlist = {xlist}
ylist = {ylist}
for (x, y, l) in zip(xlist, ylist, legends):
pylab.plot(x, y, label=l)
pylab.axhline(0, color='red', marker='o', linestyle='dashed')
pylab.xlabel("{xlabel}")
pylab.ylabel("{ylabel}")
pylab.legend()
pylab.tight_layout()
pylab.show()
'''
fh = open(save_path, 'w')
fh.write(output)
fh.close()
LOG.info(f'Run: {save_path}, to look at {xlabel} x {ylabel} plot.')
|