-
Notifications
You must be signed in to change notification settings - Fork 11
/
common.py
92 lines (71 loc) · 2.44 KB
/
common.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
#!/bin/env python3
#
# Authors: Alexander Jung <[email protected]>
#
import matplotlib as mpl
import matplotlib.pyplot as plt
SMALL_SIZE = 12
MEDIUM_SIZE = 14
LARGE_SIZE = 18
BIGGER_SIZE = 24
KBYTES = 1000.0
PATTERNS = ('-', '+', 'x', '\\', '.')
def common_style(plt):
plt.style.use('classic')
plt.tight_layout()
plt.rcParams['text.usetex'] = False
plt.rc('pdf', fonttype=42)
# plt.rcParams["font.family"] = "Arial"
# plt.rc('font', **{
# 'family': 'sans-serif',
# 'sans-serif': ['DejaVu Sans'] # ['Computer Modern']
# })
plt.rc('font',**{
'family':'sans-serif',
'sans-serif':['Helvetica']}
)
plt.rc('text', usetex=True)
# plt.rcParams['font.sans-serif'] = "Comic Sans MS"
plt.rcParams['font.family'] = "sans-serif"
plt.rc('font', size=MEDIUM_SIZE) # controls default text sizes
plt.rc('axes', titlesize=MEDIUM_SIZE) # fontsize of the axes title
plt.rc('axes', labelsize=LARGE_SIZE) # fontsize of the x and y labels
plt.rc('xtick', labelsize=LARGE_SIZE) # fontsize of the tick labels
plt.rc('ytick', labelsize=MEDIUM_SIZE) # fontsize of the tick labels
plt.rc('legend', fontsize=MEDIUM_SIZE) # legend fontsize
# plt.rc('figure', titlesize=BIGGER_SIZE, titleweight='bold') # fontsize of the figure title
def mk_groups(data, selector='mean'):
try:
newdata = data.items()
except:
return
thisgroup = []
groups = []
for key, value in newdata:
newgroups = mk_groups(value, 'mean')
if isinstance(value, dict) and selector in value:
thisgroup.append((key, value[selector]))
elif newgroups is None:
thisgroup.append((key, value))
else:
thisgroup.append((key, len(newgroups[-1])))
if groups:
groups = [g + n for n, g in zip(newgroups, groups)]
else:
groups = newgroups
return [thisgroup] + groups
def add_line(ax, xpos, ypos, height=.1):
line = plt.Line2D([xpos, xpos], [ypos, ypos + height],
transform=ax.transAxes, color='black',
linewidth=1)
line.set_clip_on(False)
ax.add_line(line)
def sizeof_fmt(num, suffix='B', last_zero=False):
for unit in ['','K','M','G']:
if abs(num) < KBYTES:
if num == 0 or num.is_integer():
return "%d%s%s" % (int(num), unit, suffix)
else:
return "%3.1f%s%s" % (num, unit, suffix)
num /= KBYTES
return "%.1f%s%s" % (num, 'Yi', suffix)