rgl:带有“扩展”的plot3d绘图符号

发布于 2025-01-10 09:51:19 字数 1246 浏览 0 评论 0原文

我正在尝试扩展可用于 3D 绘图的符号。在 2D 中,我使用:

x1 <- sort(rnorm(10))
y1 <- rnorm(10)
z1 <- rnorm(10) + atan2(x1, y1)
x2 <- sort(rnorm(10))
y2 <- rnorm(10)
z2 <- rnorm(10) + atan2(x2, y2)
x3 <- sort(rnorm(10))
y3 <- rnorm(10)
z3 <- rnorm(10) + atan2(x3, y3)
new.styles <- -1*c(9818:9824, 9829, 9830, 9831)

在 2D 中,我的绘图有效并给出了适当的符号:

plot(x1, y1, col="red", bg="red", pch=new.styles, cex = 2)

并且绘图在这里: 带有适当符号的示例 2D 绘图

但是,在 3D 中,符号无法正确转换。

rgl::plot3d(x1, y1, z1, col="red", bg="red", pch=new.styles, size = 10)

这会产生: “在此处输入图像描述”

符号将被(一个)圆圈取代。

我还尝试了 pch3d 并得到了空白图。然而,pch3d 确实可以使用“标准”绘图符号。

 rgl::pch3d(x1, y1, z1, col="red", bg="red", pch=10:19, size = 10)

我得到了情节: 带有标准符号的 3D 图

因此,至少这些符号似乎没有以 3D 形式显示。如何显示首选符号?

I am trying to extend the symbols available to me for plotting in 3D. In 2D, I use:

x1 <- sort(rnorm(10))
y1 <- rnorm(10)
z1 <- rnorm(10) + atan2(x1, y1)
x2 <- sort(rnorm(10))
y2 <- rnorm(10)
z2 <- rnorm(10) + atan2(x2, y2)
x3 <- sort(rnorm(10))
y3 <- rnorm(10)
z3 <- rnorm(10) + atan2(x3, y3)
new.styles <- -1*c(9818:9824, 9829, 9830, 9831)

In 2D, my plot works and gives the appropriate symbol:

plot(x1, y1, col="red", bg="red", pch=new.styles, cex = 2)

and the plot is here:example 2D plot with appropriate symbols

In 3D, however, the symbols do not get translated correctly.

rgl::plot3d(x1, y1, z1, col="red", bg="red", pch=new.styles, size = 10)

this yields: enter image description here

The symbols are getting replaced with (one) circle.

I also tried with pch3d and got blank plots. However, pch3d does work with the "standard" plotting symbols.

 rgl::pch3d(x1, y1, z1, col="red", bg="red", pch=10:19, size = 10)

I get the plot: 3D plot with standard symbols

So, it appears to be that at least the symbols are not displaying in 3D. How can I display the preferred symbols?

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

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

发布评论

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

评论(2

初心 2025-01-17 09:51:19

我只能使用 text3d() 获得解决方案 - 希望存在更好的解决方案。

x1 <- sort(rnorm(12))
y1 <- rnorm(12)
z1 <- rnorm(12) + atan2(x1, y1)
x2 <- sort(rnorm(12))
y2 <- rnorm(12)
z2 <- rnorm(12) + atan2(x2, y2)
x3 <- sort(rnorm(12))
y3 <- rnorm(12)
z3 <- rnorm(12) + atan2(x3, y3)
new.styles <- c(9818:9824, 9829, 9830, 9831, 9832, 9827)

rgl::open3d()
pal.col <- RColorBrewer::brewer.pal(name = "Paired", n = 12)                                        
for (i in 1:12)
    rgl::text3d(x1[i], y1[i], z1[i], col=pal.col[i], text = intToUtf8(new.styles[i]), cex = 2, usePlotmath = TRUE)
rgl::box3d()

得出的结果是:

Using text3d

这可能太复杂了,希望有更好的解决方案。

I was able to only get a solution using text3d() -- hopefully there exists a better solution.

x1 <- sort(rnorm(12))
y1 <- rnorm(12)
z1 <- rnorm(12) + atan2(x1, y1)
x2 <- sort(rnorm(12))
y2 <- rnorm(12)
z2 <- rnorm(12) + atan2(x2, y2)
x3 <- sort(rnorm(12))
y3 <- rnorm(12)
z3 <- rnorm(12) + atan2(x3, y3)
new.styles <- c(9818:9824, 9829, 9830, 9831, 9832, 9827)

rgl::open3d()
pal.col <- RColorBrewer::brewer.pal(name = "Paired", n = 12)                                        
for (i in 1:12)
    rgl::text3d(x1[i], y1[i], z1[i], col=pal.col[i], text = intToUtf8(new.styles[i]), cex = 2, usePlotmath = TRUE)
rgl::box3d()

This yields the figure:

Using text3d

This may well be too complicated, hopefully there are better solutions out there.

甜`诱少女 2025-01-17 09:51:19

这是我能做的最好的事情:

带皇冠的 3d 图片

设置纹理/形状文件:

crown <- tempfile(pattern = "crown", fileext = ".png")
png(filename = crown)
plot(1,1, ann=FALSE, axes=FALSE, pch=-9818, cex = 40, col = 2)
dev.off()

加载包,定义一个在随机点绘制纹理的函数:

library(rgl)
xyz <- cbind(c(0,1,1,0), 0, c(0,0,1,1))
add_quad_point <- function(shape = crown, sd = 3) {
  pos <- rnorm(3, sd = sd)
  m <- sweep(xyz, MARGIN=2, STATS = pos, FUN = "+")
  quads3d(m,
          texture = shape,
          texcoords = xyz[,c(1,3)],
          col = "white",
          specular = "black")
}
open3d()
replicate(10, add_quad_point())
axes3d()
## close3d()

This is the best I could do:

3d picture with crowns

Set up file for texture/shape:

crown <- tempfile(pattern = "crown", fileext = ".png")
png(filename = crown)
plot(1,1, ann=FALSE, axes=FALSE, pch=-9818, cex = 40, col = 2)
dev.off()

Load package, define a function to plot the texture at a random point:

library(rgl)
xyz <- cbind(c(0,1,1,0), 0, c(0,0,1,1))
add_quad_point <- function(shape = crown, sd = 3) {
  pos <- rnorm(3, sd = sd)
  m <- sweep(xyz, MARGIN=2, STATS = pos, FUN = "+")
  quads3d(m,
          texture = shape,
          texcoords = xyz[,c(1,3)],
          col = "white",
          specular = "black")
}
open3d()
replicate(10, add_quad_point())
axes3d()
## close3d()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文