R 中的 3D 绘图 - 使用第四维颜色

发布于 2024-12-13 15:01:05 字数 190 浏览 6 评论 0原文

我正在使用plot3d函数在我的R脚本中绘制3D图。我想添加第四个维度,即颜色。我该怎么做?

具体来说,假设我有以下代码:

plot3d(x, y, z, col=cols, size=2, type='s')

如何根据充当第四维的值向量填充 cols

I am using the plot3d function to make a 3d plot in my R script. I'd like to add a 4th dimension, which will be color. How can I do this?

Specifically, assume I have the following code:

plot3d(x, y, z, col=cols, size=2, type='s')

how would I populate cols based on a vector of values acting as my 4th dimension.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寂寞清仓 2024-12-20 15:01:05

只需制作一个颜色图,然后使用 c 变量的剪切版本对其进行索引:

x = rnorm(100)
y = rnorm(100)
z = rnorm(100)

c = z
c = cut(c, breaks=64)
cols = rainbow(64)[as.numeric(c)]

plot3d(x,y,z,col=cols)

在此处输入图像描述

Just make a colormap, and then index into it with a cut version of your c variable:

x = rnorm(100)
y = rnorm(100)
z = rnorm(100)

c = z
c = cut(c, breaks=64)
cols = rainbow(64)[as.numeric(c)]

plot3d(x,y,z,col=cols)

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文