-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplt_lat_bp.py
137 lines (106 loc) · 3.68 KB
/
plt_lat_bp.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env python3
'''Plot and save WIMA vs Baseline latency boxplot graph.'''
import sys
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
NUM_TICKS = 12
NUM_SUBTICKS = NUM_TICKS * 5
MAJ_ALPHA = 1.5
MIN_ALPHA = 0.2
LW = 1.5
X_LABEL = ''
Y_LABEL = 'E2E Flow Setup Time (ms)'
DATA_TYPE = 'latency'
GRAPH_TYPE = 'boxplot'
FILE_EXTENSION = '.png'
def format_graph(graph):
'''Configure graph properties.'''
colors = ['black', 'black', 'red', 'red']
for cap, color in zip(graph['caps'], colors):
cap.set(color=color, linewidth=LW)
for whisker, color in zip(graph['whiskers'], colors):
whisker.set(color=color, linewidth=LW)
colors = ['black', 'red']
for mean, color in zip(graph['means'], colors):
mean.set(markeredgecolor=color, linewidth=LW)
for median, color in zip(graph['medians'], colors):
median.set(color=color, linewidth=LW)
for patch, color in zip(graph['boxes'], colors):
patch.set_facecolor("None")
patch.set_edgecolor(color)
patch.set_linewidth(LW)
def format_axis(axis):
'''Uses axis to configure the graph.'''
locator = ticker.MaxNLocator
axis.xaxis.set_ticks_position('both')
axis.xaxis.set_ticks([0, 1, 2, 3])
axis.set_xticklabels(['', 'WIMA', 'Baseline', ''])
axis.yaxis.grid(which='major', linestyle='-', alpha=MAJ_ALPHA)
axis.yaxis.grid(which='minor', linestyle='-', alpha=MIN_ALPHA)
axis.set_axisbelow(True)
for iter_axis in (axis, axis.twinx()):
iter_axis.yaxis.set_major_locator(locator(NUM_TICKS))
iter_axis.yaxis.set_minor_locator(locator(NUM_SUBTICKS))
iter_axis.set_ylim(axis.get_ylim())
def format_plot(graph):
'''Uses pyplot to configure the graph.'''
plt.xlabel(X_LABEL, fontweight='bold')
plt.ylabel(Y_LABEL, fontweight='bold')
# Legend configuration
leg = plt.legend([graph["boxes"][0], graph["boxes"][1]],
['WIMA', 'Baseline'], loc='upper left',
fancybox=False, framealpha=1,
shadow=False, borderpad=1)
leg.get_frame().set_edgecolor('black')
def get_filename(conn):
'''Return filename of the figure.'''
filename = DATA_TYPE + '-'
filename += GRAPH_TYPE + '-'
filename += str(conn) + FILE_EXTENSION
return filename
def open_file(filename):
'''Return file content given filename.'''
with open(filename) as file_:
return file_.read()
def plot_graphs(graphs_dir):
'''Plot the graphs and save the figures in graphs_dir.'''
beg = 0
end = 0
inc = 0
data = []
_, axis = plt.subplots()
meanpointprops = dict(
marker='s',
markerfacecolor='None',
markeredgewidth=LW)
if graphs_dir[-1] != '/':
graphs_dir += '/'
summ = open_file('summary.csv').split(',')
beg = int(summ[4])
end = int(summ[5])
inc = int(summ[6])
conn = beg
for line in open_file('latency.raw').splitlines():
data.append([float(i) for i in line.split(',')])
if len(data) == 2:
boxplot = axis.boxplot(
data,
showfliers=False,
meanprops=meanpointprops,
meanline=False,
showmeans=True,
patch_artist=True,
notch=False,
labels=['WIMA', 'Baseline'])
format_graph(boxplot)
format_plot(boxplot)
format_axis(axis)
#plt.show()
plt.savefig(graphs_dir + get_filename(conn), dpi=600)
_, axis = plt.subplots()
data.clear()
conn += inc
if conn > end:
break
if __name__ == '__main__':
plot_graphs(sys.argv[1])