说明
如下图:
代码
import matplotlib.pyplot as plt
plt.rcParams['font.family'] = ['Microsoft YaHei']
species = (
"帝企鹅\n平均体重3700.66g",
"小企鹅\n平均体重3733.09g",
"大企鹅\n平均体重5076.02g",
)
# 柱子宽度
width = 0.5
bottom = [0, 0, 0]
plt.bar(species, [70, 31, 58], width, label='低于')
# bottom:设置柱子的最小值,目的是堆叠在第一组柱子的上面
plt.bar(species, [82, 37, 66], width, label='高于', bottom=[70, 31, 58])
plt.title("企鹅体重高于平均值的数量")
plt.legend(loc="upper right")
plt.show()
