python - python 中的多个条

标签 python matplotlib histogram

我想使用 matplotlib 绘制多个条形图。 我用过:

a=(45,22,17,28)

b=(32,17,15,27)

c=(15,18,22,25)

rects1 = plt.bar(index, a, bar_width, alpha=opacity, color='b',error_kw=error_config,  label='A')

rects2 = plt.bar(index, b, bar_width,alpha=opacity, color='r', error_kw=error_config,   label='B',bottom=a)

rects4 = plt.bar(index , c, bar_width, alpha=opacity, color='y', error_kw=error_config, label='C',bottom=a+b)

我想让c超过b超过a,但bottom=a+b不起作用...

最佳答案

它失败了,因为您无法添加元组。您需要的是 numpy 数组:

import numpy as np

a=np.array([45,22,17,28])

b=np.array([32,17,15,27])

c=np.array([15,18,22,25])

关于python - python 中的多个条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24869755/

相关文章:

python - 子程序后打印字符串

python - 将文本注释到轴并对齐为圆

r - 无法绘制直方图, 'x' 必须是数字

python - 设置图例以多行显示(在python中)

python - 我如何在 matplotlib 中设置小刻度的位置

python - 我可以通过另一个变量中的值为 seaborn distplot 着色吗?

python - 通过 bins matplotlib 标记直方图

python - Conda - 如何在现有环境中仅更新 cudatoolkit?

python - Numpy修改数组到位?

python 交互式 shell 比命令行快 16 倍——怎么了?