gpt4 book ai didi

r - 具有非完整网格的曲面图

转载 作者:行者123 更新时间:2023-12-04 12:11:43 25 4
gpt4 key购买 nike

我想要一个曲面图,但我的网格不完整。我搜索过,但没有成功。我怎样才能使以下工作:

x = c(10L, 20L, 30L, 40L, 50L, 60L, 70L, 80L, 90L, 100L, 30L, 40L, 
50L, 60L, 70L, 80L, 90L, 100L, 50L, 60L, 70L, 80L, 90L, 100L,
70L, 80L, 90L, 100L, 90L, 100L)
y = c(10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 30L, 30L, 30L, 30L, 30L, 30L,
40L, 40L, 40L, 40L, 50L, 50L)
z = c(6.093955007, 44.329214443, 149.103755156, 351.517349974,
726.51174655, 1191.039562104, 1980.245204702, 2783.308022984,
6974.563519067, 5149.396230019, 142.236259009, 321.170609648,
684.959503897, 1121.475597135, 1878.334840961, 2683.116309688,
4159.60732066, 5294.774284119, 687.430547359, 1119.765405426,
1876.57337196, 2685.951176024, 3945.696884503, 5152.986796572,
1870.78724464, 2677.744176903, 3951.928931107, 5160.295960254,
3957.503273558, 5147.237754092)

# OK but not a surface plot
scatterplot3d::scatterplot3d(x, y, z,
color = "blue", pch = 19,
type = "h",
main = "",
xlab = "x",
ylab = "y",
zlab = "z",
angle = 35,
grid = FALSE)

# Not working:
M <- plot3D::mesh(x, y, z)
R <- with (M, sqrt(x^2 + y^2 +z^2))
p <- sin(2*R)/(R+1e-3)
plot3D::slice3D(x, y, z, colvar = p,
xs = 0, ys = c(-4, 0, 4), zs = NULL)
plot3D::isosurf3D(x, y, z, colvar = p, level = 0, col = "red")

最佳答案

这与其说是一个完整的答案,不如说是一个提示:

library(plotly)
plot_ly(z = ~volcano) %>% add_surface()

是做这种情节的好方法。所以对于你的例子:
x <- c(10L, 20L, 30L, 40L, 50L, 60L, 70L, 80L, 90L, 100L, 30L, 40L, 
50L, 60L, 70L, 80L, 90L, 100L, 50L, 60L, 70L, 80L, 90L, 100L,
70L, 80L, 90L, 100L, 90L, 100L)
y <- c(10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 30L, 30L, 30L, 30L, 30L, 30L,
40L, 40L, 40L, 40L, 50L, 50L)
z <- c(6.093955007, 44.329214443, 149.103755156, 351.517349974,
726.51174655, 1191.039562104, 1980.245204702, 2783.308022984,
6974.563519067, 5149.396230019, 142.236259009, 321.170609648,
684.959503897, 1121.475597135, 1878.334840961, 2683.116309688,
4159.60732066, 5294.774284119, 687.430547359, 1119.765405426,
1876.57337196, 2685.951176024, 3945.696884503, 5152.986796572,
1870.78724464, 2677.744176903, 3951.928931107, 5160.295960254,
3957.503273558, 5147.237754092)

library(plotly)
m <- matrix(c(x,y,z), nrow = 3)
plot_ly(z = ~m) %>% add_surface()

产生

enter image description here

..这是第一步,但 x 轴的缩放仍然存在一些问题。我认为解决方案的关键是设置整个(稀疏)矩阵,然后绘制它。
x <- c(10L, 20L, 30L, 40L, 50L, 60L, 70L, 80L, 90L, 100L, 30L, 40L, 
50L, 60L, 70L, 80L, 90L, 100L, 50L, 60L, 70L, 80L, 90L, 100L,
70L, 80L, 90L, 100L, 90L, 100L)
y <- c(10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 30L, 30L, 30L, 30L, 30L, 30L,
40L, 40L, 40L, 40L, 50L, 50L)
z <- c(6.093955007, 44.329214443, 149.103755156, 351.517349974,
726.51174655, 1191.039562104, 1980.245204702, 2783.308022984,
6974.563519067, 5149.396230019, 142.236259009, 321.170609648,
684.959503897, 1121.475597135, 1878.334840961, 2683.116309688,
4159.60732066, 5294.774284119, 687.430547359, 1119.765405426,
1876.57337196, 2685.951176024, 3945.696884503, 5152.986796572,
1870.78724464, 2677.744176903, 3951.928931107, 5160.295960254,
3957.503273558, 5147.237754092)

xx <- 1:100L
yy <- 1:100L
zz <- matrix(0, nrow = 100, ncol = 100)

for (i in 1:length(x)){
zz[x[i], y[i]] <- z[i]
}

library(plotly)
plot_ly(z = ~zz) %>% add_surface()

产生

enter image description here

这基本上是您的数据假设的内容。

希望我也能弄清楚。
希望这会有所帮助。

关于r - 具有非完整网格的曲面图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50247697/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com