import matplotlib.pyplot as plt import numpy as np import matplotlib as mpl mpl.rcParams["font.sans-serif"] = ["SimHei"] mpl.rcParams["axes.unicode_minus"] = False scoreT1 = np.random.randint(0, 100, 100) scoreT2 = np.random.randint(0, 100, 100) x = [scoreT1, scoreT2] colors = ["#8dd3c7", "#bebada"] labels = ["班级A", "班级B"] bins = range(0, 101, 10) plt.hist(x, bins=bins, color=colors, histtype="stepfilled", rwidth=10, stacked=True, label=labels) plt.xlabel("测试成绩") plt.ylabel("学生人数") plt.title("不同班级的测试成绩的直方图") plt.legend() plt.show()
原文地址:https://www.cnblogs.com/czz0508/p/10460440.html
时间: 2024-10-03 12:38:11