我试着用pandas/matplotlib制作学生作业成绩的条形图。我可以做条形图没有问题,但我想做的是根据学生的分数选择颜色。例如,我希望我可以将分数设为<;=50红色,>;50和<;=75黄色,等等
这是我目前所在的地方
import pandas as pd
import matplotlib.pyplot as plt
# make some arrays
score = [100, 50, 43, 67, 89, 2, 13, 56, 22, -1, 53]
homework_problem = ['A', 'B', 'C', 'B', 'A', 'D', 'D', 'A', 'C', 'D', 'B']
topic = ['F', 'G', 'H', 'G', 'H', 'F', 'H', 'G', 'G', 'F', 'H']
# put the arrays into a pandas df
df = pd.DataFrame()
df['score'] = score
df['homework_problem'] = homework_problem
df['topic'] = topic
#make sure it looks okay
print(df)
# let's groupby and plot
df.groupby(['homework_problem','score'])['topic'].size().unstack().plot(kind='bar',stacked=True, title = "Test")
plt.show()
你可以试试这个:
输出:
^{pr2}$相关问题 更多 >
编程相关推荐