首页 > 解决方案 > 根据每个数据点的实际值绘制 3D 点的颜色

问题描述

我有一个 3D 斜率数组 X。我想绘制每个数据点并根据实际值对点进行颜色编码。有三个可能的值。

如果斜率大于 80,则将数据点绘制为红色。如果斜率大于 -80 则为蓝色,否则为绿色。

我也想要传说。谢谢

我试图创造一些东西,但没有做对。

#Make the array to 2D with X, Y, Z axis
X=fits.transpose(2,0,1).reshape(-1,3)
print(X.shape)


kcolors = ['red' if slope greater 0.2  elif slope greater -0.2 'green'  else 'blue' for slope in X]

plt.scatter(transformed[:,0], transformed[:,1], transformed[:,2], c=kcolors)


File "<ipython-input-26-4efc22ca2a34>", line 6
kcolors = ['red' if slope > 0.2  elif slope > -0.2 'green'  else 'blue' for slope in points]

SyntaxError:无效的语法

标签: python-3.xplotscatter-plot

解决方案


我试过了

colors = []
for slope in Xpoints[0]:
    if slope > 0.2:
        colors.append('r')
    elif slope < -0.2:
        colors.append('g') 
    else:
        colors.append('b')

这似乎有效。有没有更好的方法呢?


推荐阅读