指定散点图中每个点的颜色(matplotlib) [英] Specify color of each point in scatter plot (matplotlib)

查看:2077
本文介绍了指定散点图中每个点的颜色(matplotlib)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用matplotlib创建的3D图,并且有一个与每个点相对应的rbg值列表。

I have a 3D Plot that I created using matplotlib, and I have a list of rbg values that correspond to each point.

我有X,Y,和Z数据,然后有一个格式的颜色列表:

I have the X, Y, and Z data, and then I have a "color list" of the form:

[ (r,g,b), (r,g,b), ... , (r,g,b) ]

到匹配每个(x,y,z)点。

to match each (x, y, z) point.

现在,我有

fig = plt.figure()
ax = fig.add_subplot(111, projection = '3d')

ax.scatter(X, Y, Z)
plt.show()

合并这些rgb元组的适当方法是什么,以便每个点

What's the appropriate way to incorporate those rgb tuples so that each point will be assigned a specific color?

推荐答案

我使用了 for 循环分别将每种颜色分配给每个点。这是我的代码:

I used a for loop to individually assign each color to each point. Here is my code:

X = [1, 2, 3]
Y = [2, 5, 8]
Z = [6, 4, 5]
colors=["#0000FF", "#00FF00", "#FF0066"]

fig = plt.figure()
ax = fig.add_subplot(111, projection = '3d')


for i in range(len(X)):
    ax.scatter(X[i], Y[i], Z[i], color=colors[i])
plt.show()

for 循环逐点进行(因此, [i] 每个X,Y,Z值的前面),然后逐一给出颜色。我以十六进制颜色作为示例,但如果您愿意,可以使用其他颜色。

The for loop goes point by point (hence the [i] in front of each X,Y,Z value) and gives a color one by one. I used hex colors for my example, but you could probably use something else if you wanted.

这篇关于指定散点图中每个点的颜色(matplotlib)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆