-
Notifications
You must be signed in to change notification settings - Fork 0
/
figures.py
56 lines (48 loc) · 1.37 KB
/
figures.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
import numpy as np
import matplotlib.pyplot as plt
def plot_bar_figure(
k8s,
nomad,
swarm,
ylabel,
xlabel,
xtick_labels,
figure_path
):
ind = np.arange(len(xtick_labels))
width = 0.27
fig = plt.figure()
ax = fig.add_subplot(111)
k8s_rects = ax.bar(ind, k8s, width, color='r')
if nomad:
nomad_rects = ax.bar(ind + width, nomad, width, color='g')
bar_width = ind + width * 2
if swarm and not nomad:
bar_width = ind + width
swarm_rects = ax.bar(bar_width, swarm, width, color='b')
legend_title = ('k8s', 'swarm')
if nomad:
legend_title = ('k8s', 'nomad', 'swarm',)
ax.set_ylabel(ylabel)
ax.set_xlabel(xlabel)
ax.set_xticks(ind + width)
ax.set_xticklabels(xtick_labels)
ax.legend(
legend_title,
bbox_to_anchor=(0, 1.05, 1, 0.2), loc="lower left",
fancybox=True, shadow=True, ncol=5, mode="expand"
)
def _auto_label(rects):
for rect in rects:
h = rect.get_height()
ax.text(
rect.get_x() + rect.get_width() / 2.,
1.05 * h, '%d' % int(h),
ha='center', va='bottom'
)
_auto_label(k8s_rects)
if nomad:
_auto_label(nomad_rects)
_auto_label(swarm_rects)
plt.savefig('{0}.png'.format(figure_path))
plt.close(fig)