ValueError:无法将参数类型 <type 'bool'> 转换为 rgba 数组?
我正在学习用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')
2 个回答
0
听起来你应该给facecolors
这个参数提供一组颜色值,而不是给它True
。
1
你给面颜色传了一个布尔值(真或假)。
这个参数是这样定义的:
facecolor or facecolors: matplotlib color arg or sequence of rgba tuples
只要把 facecolor = None
这样写就可以了。不过你可能不想这样,因为这样两个图的颜色会一样。如果你去掉这个参数,系统会自动给你不同的颜色。如果你还是想要自定义颜色,最简单的方法就是用 matplotlib 支持的颜色名称,比如 'yellow'(黄色)、'red'(红色)等等。