【问题标题】:ValueError: Cannot convert argument type <type 'bool'> to rgba array?ValueError:无法将参数类型 <type 'bool'> 转换为 rgba 数组?
【发布时间】:2011-12-27 11:22:09
【问题描述】:

我正在学习使用 matplotlib 绘制散点图。但是,有一个错误,它似乎与颜色参数有关。谁能解释我的错误?我用谷歌搜索但没有找到答案。提前致谢。

xActA = range(10)
yActA = np.random.randn(10)
xActQ = range(10)
yActQ = np.random.randn(10)
xRa = np.random.randn(10)
yRa = np.random.randn(10)

f1 = figure(1)
scatter(xActA, yActA, c ='b', marker = 'o', facecolors = True, label = 'Answers')
scatter(xActQ, yActQ,   c ='r', marker = 'o', facecolors = True, label = 'Questions')
xscale('log')
yscale('log')
title('User activity')
xlabel('Number of posts')
ylabel('Number of users')
legend()
f1.show()
f1.savefig('figure7_test.png')

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    你给 facecolors 一个布尔值。
    参数定义为:

    facecolor or facecolors: matplotlib color arg or sequence of rgba tuples  
    

    只需创建facecolor = None 即可。你可能不想要这个,因为你得到了两个图的相同颜色。如果您消除该参数,您将获得自动颜色。如果您仍然需要自定义颜色,最简单的方法是将它们表示为 matplotlib 颜色('黄色、'红色'等)

    【讨论】:

    • 谢谢。我将代码更改为:ax1 = scatter(xActA, yActA, color = 'blue',s = 20),并且出现了一个新错误:return array(a, dtype, copy=False, order=order) ValueError: setting带有序列的数组元素。并且有一个没有散点的情节,但里面有其他任何东西。你能告诉我是什么错误吗?非常感谢。
    • @AnneS 从您提供的数据中很难说。通过这些更改,它仍然应该可以工作。所以问题出在你没有展示的其他地方。您应该在另一个问题中发布您的新代码和 full 回溯。但首先,尝试了解程序何时运行,并分析您所做的更改以使其失败
    【解决方案2】:

    听起来您应该为facecolors 参数提供一组颜色值,而不是True

    【讨论】:

      猜你喜欢
      • 2020-09-03
      • 2020-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      相关资源
      最近更新 更多