| name | grade |
|---|---|
| chandler | A |
| joey | B |
| phoebe | B |
| monica | C |
| ross | A |
| rachel | B |
| mike | C |
| gunther | A |
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
class2 = [['chandler','A'],
['joey','B'],
['phoebe','B'],
['monica', 'C'],
['ross','A'],
['rachel','B'],
['mike','C'],
['gunther','A']]
data= pd.DataFrame(class2, columns=['name','grade'])
print(data)
fig, ax = plt.subplots()
ax= sns.countplot(x='grade', data = data, color='yellow')
plt.show()
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:
gb = data.groupby('grade').apply(len)
for student, grade in class2:
fig, ax = plt.subplots()
colors = ['red' if a == grade else 'grey' for a in gb.index.values ]
gb.plot(kind='bar', color = colors, ax=ax)
plt.show()