-
Notifications
You must be signed in to change notification settings - Fork 1
/
draw_pic.py
111 lines (94 loc) · 3.57 KB
/
draw_pic.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from matplotlib.pyplot import savefig
from os import listdir, path, mkdir
import sys
output_order = ['geotrucrowdgreedy',
'geotrucrowdhgr',
'geocrowdgreedy',
'geocrowdllep',
'geocrowdnnp',
'rdbscdivideandconquer',
'rdbscsampling',
'workerselectprogressive',
'workerselectdp',
'workerselectbb',
'workerselectha'
]
__author__ = 'Jian Xun'
LABEL = {
'geocrowdgreedy': 'G-greedy',
'geocrowdnnp': 'G-nnp',
'geocrowdllep': 'G-llep',
'geotrucrowdgreedy': 'GT-greedy',
'geotrucrowdhgr': 'GT-HGR',
'rdbscsampling': 'RDB-sam',
'rdbscdivideandconquer': 'RDB-d&c',
'workerselectprogressive': 'PRS',
'workerselectdp': 'DP',
'workerselectbb': 'BB',
'workerselectha': 'HA'
}
MARKER = {
'geocrowdgreedy': {'marker': 's', 'mew': 1, 'markersize': 14},
'geocrowdnnp': {'marker': '^', 'mew': 1, 'markersize': 14},
'geocrowdllep': {'marker': 'd', 'mew': 1, 'markersize': 14},
'geotrucrowdgreedy': {'marker': '*', 'mew': 1, 'markersize': 16},
'geotrucrowdhgr': {'marker': 'p', 'mew': 1, 'markersize': 16},
'rdbscsampling': {'marker': '+', 'mew': 2, 'markersize': 14},
'rdbscdivideandconquer': {'marker': 'x', 'mew': 2, 'markersize': 14},
'workerselectprogressive': {'marker': 'o', 'mew': 2, 'markersize': 14},
'workerselectdp': {'marker': ',', 'mew': 1, 'markersize': 16},
'workerselectbb': {'marker': 'v', 'mew': 1, 'markersize': 14},
'workerselectha': {'marker': '|', 'mew': 1, 'markersize': 14}
}
def read_file(file_path):
datas = []
variable = file_path.split('/')[-1].split('_', 1)[1].split('.')[0]
dist = file_path.split('/')[-1].split('_', 1)[0]
with open(file_path, 'r') as infile:
line = infile.readline().strip()
while line != '':
data = {
'distribution': dist,
'y_label': line,
'x_label': variable,
'x_series': infile.readline().split('\t')[1:],
'lines': {}
}
line = infile.readline().strip()
while '\t' in line:
sp = line.split('\t')
data['lines'][sp[0]] = sp[1:]
line = infile.readline().strip()
datas.append(data)
return datas
def draw(data, suffix):
line_width = 2
legend_text_size = 18
plots = []
plt.figure(figsize=(9, 9))
for label in output_order:
if label in data['lines']:
p, = plt.plot(data['lines'][label], color='k', label=LABEL[label], markerfacecolor='w', linewidth=line_width, **MARKER[label])
plots.append(p)
plt.xticks(range(len(data['x_series'])), data['x_series'], size='medium')
plt.xlabel(data['x_label'], fontsize=legend_text_size)
plt.ylabel(data['y_label'], fontsize=legend_text_size)
plt.show()
# plt.legend(handles=plots)
# save picture into 'pics' directory
if not path.isdir('./pics'):
mkdir('./pics')
savefig('./pics/' + data['distribution'] + '_' + data['x_label'] + '_' + data['y_label'] + '.' + suffix)
def main():
files = listdir('./results')
for file_name in files:
if '.csv' in file_name:
datas = read_file(path.join('results', file_name))
for data in datas:
if data['y_label'] != 'worker_num' and data['y_label'] != 'task_num':
draw(data, 'eps')
if __name__ == '__main__':
main()