一、plt画堆积柱形图
只需要这个一个参数(bottom=y)就OK了
import matplotlib.pyplot as plt import matplotlib as mpl mpl.rcParams["font.sans-serif"] = ["SimHei"] mpl.rcParams["axes.unicode_minus"] = False x = [1, 2, 3, 4, 5] y = [6, 10, 4, 5, 1] y1 = [2, 6, 3, 8, 5] plt.figure(figsize=(16,12)) plt.bar(x, y, align="center", color="#66c2a5", tick_label=["A", "B", "C", "D", "E"], label="班级A") plt.bar(x, y1, align="center", bottom=y, color="#8da0cb", label="班级B") plt.xlabel("测试难度") plt.ylabel("试卷份数") plt.legend() plt.show()
二、