name | grade |
---|---|
chandler | A |
joey | B |
phoebe | B |
monica | C |
ross | A |
rachel | B |
mike | C |
gunther | A |
JavaScript
x
18
18
1
import pandas as pd
2
import matplotlib.pyplot as plt
3
import seaborn as sns
4
5
class2 = [['chandler','A'],
6
['joey','B'],
7
['phoebe','B'],
8
['monica', 'C'],
9
['ross','A'],
10
['rachel','B'],
11
['mike','C'],
12
['gunther','A']]
13
data= pd.DataFrame(class2, columns=['name','grade'])
14
print(data)
15
fig, ax = plt.subplots()
16
ax= sns.countplot(x='grade', data = data, color='yellow')
17
plt.show()
18
How to proceed from here if I want to make 8 different report cards (small graph in A4 size paper), and highlight the grade category in which the student belongs?
Edit: I want to show gunther in which group he falls in. And I want to show this to all students in which category they belong. For that, I need 8 different images to send them. How to get those 8 images?
Advertisement
Answer
If I understand correctly, you want something like this:
JavaScript
1
11
11
1
gb = data.groupby('grade').apply(len)
2
3
4
for student, grade in class2:
5
fig, ax = plt.subplots()
6
7
colors = ['red' if a == grade else 'grey' for a in gb.index.values ]
8
9
gb.plot(kind='bar', color = colors, ax=ax)
10
plt.show()
11