import matplotlib.pyplot as plt import matplotlib as mpl baseclass=[1,2,3,4] name = ['class1','class2','class3','class4'] scores = [67,79,89,50] plt.title("title") # 图形标题 plt.xlabel("x labal") # x轴名称 plt.ylabel("y label") # y 轴名称 plt.xticks(baseclass,name) # x轴替换为名字 plt.bar(baseclass,scores) #设置每个轴的值 for i in range(0,len(baseclass)): print(i) plt.text(baseclass[i],scores[i]+1,scores[i]) plt.show()
结果如下