-
Notifications
You must be signed in to change notification settings - Fork 1
/
stacked_plots.py
48 lines (42 loc) · 1.81 KB
/
stacked_plots.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
import os
import numpy as np
import matplotlib.pyplot as plt
from args import init_arguments
def plot_together(loadPATH, COLORS, i, label, fn):
arr_globalv = np.loadtxt(loadPATH)
m = arr_globalv.mean(axis=0)
err = arr_globalv.std(axis=0)
x = np.arange(len(m))
plt.plot(x, m, c=COLORS['deep'][i], label=label)
plt.legend()
plt.fill_between(x, m-err, m+err, facecolor=COLORS['light'][i], alpha=.2)
plt.title('The Training Curve of The Global Best Value')
plt.xlabel('Epoch')
plt.ylabel('Global Best Value')
plt.grid(linestyle='--')
plt.savefig(fn)
print('The plot is save as')
print('-->', fn)
if __name__ == '__main__':
args = init_arguments().parse_args()
if not os.path.exists(args.savePATH):
os.makedirs(args.savePATH)
COLORS = {
'deep': ('salmon', 'seagreen', 'royalblue', 'mediumorchid'),
'light': ('sandybrown', 'limegreen', '#089FFF', 'violet')
}
for d in ('10', '20'):
# Plot different algorithms together
for OBJ in (1, 2):
plt.figure()
fn = os.path.join(args.savePATH, 'plot_globalv_algorithms_f' + str(OBJ) + '_d' + d + '.png')
for i, A in enumerate(('CS', 'BA', 'FPA')):
loadPATH = os.path.join('./output_r20/f' + str(OBJ) + 'd' + d, A, 'arr_globalv.txt')
plot_together(loadPATH, COLORS, i, A, fn)
# Plot different objective functions together
for A in ('CS', 'BA', 'FPA'):
plt.figure()
fn = os.path.join(args.savePATH, 'plot_globalv_functions_' + A + '_d' + d + '.png')
for OBJ in (1, 2):
loadPATH = os.path.join('./output_r20/f' + str(OBJ) + 'd' + d, A, 'arr_globalv.txt')
plot_together(loadPATH, COLORS, OBJ-1, 'function '+ str(OBJ), fn)