Newer
Older
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
import enum, sys
import numpy as np
import matplotlib.pyplot as plt
class PlotName(enum.Enum):
DEVICE_DRIVER_XR = 'dev-drv-xr'
plot_name = PlotName.__members__.get(sys.argv[1])
if plot_name is None: raise Exception('Unsupported plot: {:s}'.format(str(plot_name)))
PLOTS = {
PlotName.DEVICE_DRIVER_XR: (
#'Device Driver - XR', '0.0001-0.25', [
# ('GetConfig', [0,0,0,0,0,0,0,0,0,77,1,1,0,0]),
# ('SetConfig', [0,15,17,7,0,0,0,0,0,0,34,3,2,0]),
# ('DeleteConfig', [23,16,0,0,0,0,0,0,0,1,32,5,1,0]),
#]),
'Device Driver - XR', '0.0001-0.25', [
('GetConfig', [0,0,0,0,0,0,0,0,0,77,1,1,0,0]),
('SetConfig', [0,0,0,0,0,0,0,0,0,0,34,3,2,0]),
('DeleteConfig', [0,0,0,0,0,0,0,0,0,1,32,5,1,0]),
]),
}
BINS_RANGES = {
'0.0001-100' : [0, 0.0001, 0.00025, 0.0005, 0.00075, 0.001, 0.0025, 0.005, 0.0075,
0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10,
25, 50, 75, 100, 200],
'0.0001-1' : [0, 0.0001, 0.00025, 0.0005, 0.00075, 0.001, 0.0025, 0.005, 0.0075,
0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1],
'0.0001-0.25' : [0, 0.0001, 0.00025, 0.0005, 0.00075, 0.001, 0.0025, 0.005, 0.0075,
0.01, 0.025, 0.05, 0.075, 0.1, 0.25],
'0.001-100' : [0, 0.001, 0.0025, 0.005, 0.0075, 0.01, 0.025, 0.05, 0.075,
0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10, 25, 50, 75, 100, 200],
'0.001-7.5' : [0, 0.001, 0.0025, 0.005, 0.0075, 0.01, 0.025, 0.05, 0.075,
0.1, 0.25, 0.5, 0.75, 1, 2.5, 5, 7.5, 10],
'0.01-5' : [0, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5],
}
# plot the cumulative histogram
fig, ax = plt.subplots(figsize=(8, 8))
bins = PLOTS[plot_name][1]
if isinstance(bins, str): bins = BINS_RANGES[PLOTS[plot_name][1]]
bins = np.array(bins).astype(float)
for label, counts in PLOTS[plot_name][2]:
counts = np.array(counts).astype(float)
assert len(bins) == len(counts) + 1
centroids = (bins[1:] + bins[:-1]) / 2
ax.hist(centroids, bins=bins, weights=counts, range=(min(bins), max(bins)), density=True,
histtype='step', cumulative=True, label=label)
ax.grid(True)
ax.legend(loc='upper left')
ax.set_title(PLOTS[plot_name][0])
ax.set_xlabel('seconds')
ax.set_ylabel('Likelihood of occurrence')
plt.xscale('log')
plt.savefig('{:s}.png'.format(plot_name.value), dpi = (600))
plt.show()