-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathmarks_barchart_2.py
More file actions
51 lines (44 loc) · 1.09 KB
/
marks_barchart_2.py
File metadata and controls
51 lines (44 loc) · 1.09 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
import itertools
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
allmarks = {
'Kiran' : {
'Maths' : 78,
'Science' : 82,
'Social': 87,
'English': 52,
'Hindi': 58,
'Kannada': 62
},
'Kavita' : {
'Maths' : 75,
'Science' : 80,
'Social': 87,
'English': 68,
'Hindi': 69,
'Kannada': 78
},
'Ahmed' : {
'Maths' : 70,
'Science' : 88,
'Social': 67,
'English': 59,
'Hindi': 78,
'Kannada': 90
}
}
mpl.style.use('seaborn')
plt.figure(figsize=(12, 9))
barwidth = 1 / (1 + len(allmarks))
# Draw the graph
for i, (student, marks) in enumerate(allmarks.items()):
subjects = marks.keys()
plt.bar(np.arange(len(subjects))+i*barwidth, tuple(marks.values()), width=barwidth, align='center', label=student)
# Add useful text to the graph
plt.ylabel('%')
plt.title('Marks by Subject')
plt.xticks(np.arange(len(subjects))+barwidth*(len(allmarks)/2), subjects)
plt.legend()
# Save the graph in a file
plt.savefig('allmarks.png')