python - Matplotlib条形图错误: "the truth value of an array with more than one element is ambiguous. use a.any() or a.all()"

标签 python python-2.7 matplotlib

我在matplotlib中制作条形图,出现如下错误:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

我的代码是这样的:

N = 5
set_A = (Table1['A'], Table1['B'],
        Table1['C'], Table1['D'],
        Table1['E'])
ind = np.arange(N)
width = 0.35
plt.subplot(111)
rects1 = plt.bar(ind, set_A, width, color='g')
set_B = (Table2['A'], Table2['B'],
         Table2['C'], Table2['D'],
         Table2['E'])
rects2 = plt.bar(ind+width, set_B, width, color='b')

错误指向的行是

rects1 = plt.bar(ind, set_A, width, color='g')

我不太明白这是怎么回事。代码几乎直接取自 http://matplotlib.org/users/screenshots.html 的示例。

最佳答案

我的表 1 的格式不对:它有 2 行,而不是我假设的 1 行。这个“表 1['A']”有 2 个元素,而不是 1 个。

关于python - Matplotlib条形图错误: "the truth value of an array with more than one element is ambiguous. use a.any() or a.all()",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17834729/

相关文章:

python - 在 Pillow 中确定带有换行符的字符串的像素高度

python - 使用 xyz 数据框在 Python 中生成热图

python - 具有 3 个变量的 numpy 直方图

java - Java中多字段比较对象-Python中的dict方法

python - 修复 Excel 文件

python - 从 gpx 数据中滤除噪音

matplotlib - 如何将多个 matplotlib 图形合并为一个图形?

python - 如何将列表作为参数函数传递到 Python 3.2.3 中的 timeit 调用中?

Python:任何()意外的表现

python - 类型错误 : argument of type 'NoneType' is not iterable