-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchart.py
44 lines (39 loc) · 1.22 KB
/
chart.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
#!/usr/bin/python3
import matplotlib.pyplot as plt
import numpy as np
import json
def main():
import argparse
parser = argparse.ArgumentParser("chart", "Script for drawing charts from golf")
parser.add_argument("--source", type=str, default="results.json")
args = parser.parse_args()
with open(args.source, "r") as jf:
source = json.load(jf)
entries = []
problems = []
for lang, ldata in source.items():
for user, p in ldata.items():
entries.append((lang,user))
if len(p) > len(problems):
problems = p
data_counts = {
p : np.array(
[
source[lang][user].get(p,0) for lang,user in entries
]
) for p in problems
}
print(data_counts)
entries = tuple([f"{lang}\n{user}" for lang,user in entries])
width = 0.4
fix, ax = plt.subplots()
bottom = np.zeros(len(entries))
for problem, counts in data_counts.items():
plot = ax.bar(entries, counts, width, label=problem, bottom=bottom)
bottom += counts
ax.bar_label(plot, label_type='center')
ax.set_title('Code Golf Scores')
ax.legend()
plt.savefig("figure.png")
if __name__ == "__main__":
main()