-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathchartstat.py
More file actions
76 lines (60 loc) · 2.68 KB
/
Copy pathchartstat.py
File metadata and controls
76 lines (60 loc) · 2.68 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
import utils
def add_labels(rects, pos):
for i, rect in enumerate(rects):
if rect.get_height() > 0:
plt.text(rect.get_x() + rect.get_width() / 2, pos[i], rect.get_height(), ha='center', va='bottom', fontsize=8.5)
rect.set_edgecolor('white')
def draw_bar_chart(workloads):
utils.setup_font()
member_stat = workloads['member_stat']
member_name = []
plan_hours = []
actual_hours = []
new_work_hours = []
n_groups = len(member_stat)
label_hours = []
label_names_list = []
labels = [value['new_work_label'] for value in member_stat.values()]
label_names = labels[0].keys()
bar_colors_palette = ["#6E7074", "#61A0A8", "#749F83", "#BDA29A", "#91C7AE", "#D48265"]
for label_name in label_names:
label_hours.append([label[label_name] for label in labels])
label_names_list.append(label_name)
label_hours_tuple = list(map(tuple, label_hours))
for name in member_stat:
member_name.append(name)
plan_hours.append(member_stat[name]['plan_hours'])
actual_hours.append(member_stat[name]['actual_hours'])
new_work_hours.append(member_stat[name]['new_work_hours'])
member_name = tuple(member_name)
plan_hours = tuple(plan_hours)
actual_hours = tuple(actual_hours)
index = np.arange(n_groups)
bar_width = 0.32
opacity = 0.85
rects_plan_hours = plt.bar(index - bar_width, plan_hours, bar_width, alpha=opacity, color='#4783c1', label='plan_hours')
rects_actual_hours = plt.bar(index, actual_hours, bar_width, alpha=opacity, color='#c45247', label='actual_hours')
for i in range(len(label_hours_tuple)):
label_hours_tuple[i] = np.array(label_hours_tuple[i])
rects_new_hours = plt.bar(index + bar_width, label_hours_tuple[i], bar_width, alpha=opacity, color=bar_colors_palette[i],
label=str(label_names_list[i]), bottom=np.sum(label_hours_tuple[0:i], axis=0))
add_labels(rects_new_hours, np.sum(label_hours_tuple[0:i], axis=0) + label_hours_tuple[i]/2)
plt.xlabel('member_name')
plt.ylabel('hours')
plt.title('work hours by members')
plt.xticks(index, member_name)
hours_max_index = actual_hours.index(max(actual_hours))
plt.ylim(0, actual_hours[hours_max_index] + 40)
plt.legend(loc='best', fontsize=8)
add_labels(rects_plan_hours, plan_hours)
add_labels(rects_actual_hours, actual_hours)
plt.tight_layout()
plt.savefig('img/work_hours_chart.png')
print('------------> Save the bar chart successfully.')
# plt.show()