python-3.x - 根据每个数据点的实际值绘制 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:无效的语法
解决方案
我试过了
colors = []
for slope in Xpoints[0]:
if slope > 0.2:
colors.append('r')
elif slope < -0.2:
colors.append('g')
else:
colors.append('b')
这似乎有效。有没有更好的方法呢?
推荐阅读
- html - css mix-blend-mode 屏幕错误从父小部件获取边框半径
- python - pip 的依赖解析器需要很长时间才能解决冲突
- go - 结构变量未保存
- python - 如何在使用 Glob 和 OS 时并排打印文件夹名称和文件名称?
- sql - 在 WHERE 子句中使用 select 的别名会导致错误:“Missing FROM-clause entry for a table”
- mysql - 如何延迟删除?
- sql - sql 数据透视表 为 PIV 多次指定了“CreateDate”列
- git - 来自私有 git 存储库的 Golang 和依赖项
- regex - Visual Studio Find in Files 在其他字符串中搜索确切的字符串
- mysql - 为什么克隆 RDS 集群比 snapc 更快、更节省空间