matplotlib–多数据柱状图
'''多数据并列柱状图'''import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
mpl.rcParams["font.sans-serif"]=["SimHei"]
mpl.rcParams["axes.unicode_minus"]=Falsex=np.arange(5)
y=[6,10,4,5,1]
y1=[2,6,3,8,5]bar_width=0.35
tick_label=["A","B","C","D","E"]plt.bar(x,y,bar_width,color="c",align="center",label="班级A",alpha=0.5)
plt.bar(x+bar_width,y1,bar_width,color="b",align="center",label="班级B",alpha=0.5)plt.xlabel("难度测试")
plt.ylabel("试卷份数")plt.xticks(x+bar_width/2,tick_label)
plt.legend()
plt.show()
文章图片
'''多数据并列柱状图'''import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
mpl.rcParams["font.sans-serif"]=["SimHei"]
mpl.rcParams["axes.unicode_minus"]=Falsex=np.arange(5)
y=[6,10,4,5,1]
y1=[2,6,3,8,5]bar_width=0.35
tick_label=["A","B","C","D","E"]plt.bar(x,y,bar_width,color="c",align="center",label="班级A",alpha=0.5)
plt.bar(x+bar_width,y1,bar_width,color="b",align="center",label="班级B",alpha=0.5)plt.xlabel("难度测试")
plt.ylabel("试卷份数")plt.xticks(x+bar_width/2,tick_label)
plt.legend()
plt.show()'''多数据条形柱状图'''
plt.barh(x,y,bar_width,color="c",align="center",label="班级A",alpha=0.5)
plt.barh(x+bar_width,y1,bar_width,color="b",align="center",label="班级B",alpha=0.5)plt.xlabel("难度测试")
plt.ylabel("试卷份数")plt.xticks(x+bar_width/2,tick_label)
plt.legend()
plt.show()
【matplotlib--多数据柱状图】
文章图片