【发布时间】:2015-11-06 00:48:49
【问题描述】:
尝试在 matplotlib 中创建散点图时,我不知道如何使用颜色。
我正在尝试绘制具有不同颜色点的多个散点图以显示集群。
colors=['#12efff','#eee111','#eee00f','#e00fff','#123456','#abc222','#000000','#123fff','#1eff1f','#2edf4f','#2eaf9f','#22222f'
'#eeeff1','#eee112','#00ef00','#aa0000','#0000aa','#000999','#32efff','#23ef68','#2e3f56','#7eef1f','#eeef11']
C=1
fig = plt.figure()
ax = fig.gca(projection='3d')
for fgroups in groups:
X=[np.random.rand(50),np.random.rand(50),np.random.rand(50)]
y=[np.random.rand(50),np.random.rand(50),np.random.rand(50)]
Z=[np.random.rand(50),np.random.rand(50),np.random.rand(50)]
C=(C+1) % len(colors)
ax.scatter(X,Y,Z, s=20, c=colors[C], depthshade=True)
plt.show()
我得到的错误如下:
ValueError: to_rgba: Invalid rgba arg "#" to_rgb:无效的 rgb 参数“#” 无法将字符串转换为浮点数:#
它似乎将这些 rgb 参数视为浮点数。
但是在 matplotlib 文档中,颜色是用这种风格写的 http://matplotlib.org/api/colors_api.html
我错过了什么?
【问题讨论】:
-
minimal reproducible example 对我们很有帮助。
标签: python matplotlib scatter-plot