gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 19:23:47 26 4
gpt4 key购买 nike

我在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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com