我尝试使用plot_ly生成3D表面图:
rm(list=ls())
set.seed(42)
x_val <- seq(-2,2,0.1)
y_val <- seq(0,1,0.1)
zz <- matrix(NA, nrow = length(x_val), ncol = length(y_val))
for(i in 1:length(x_val)){
for(j in 1:length(y_val)){
zz[i,j] <- rnorm(1, x_val[i], y_val[j]+0.01)
}
}
plot_ly(x = x_val, y = y_val, z = zz, type = "surface")
结果图如下:
如您所见,x_axis的范围介于-2和2之间,但是仅绘制了介于-1和-2之间的值。
如何绘制整个x值的结果?
根据评论中的建议,我尝试实施此问题(plotly 3d surface - change cube to rectangular space)的解决方案。
但是,使用
plot_ly(x = x_val, y = y_val, z = zz, type = "surface") %>%
layout(
scene = list(
xaxis = list(range = c(-2,2)),
yaxis = list(range = c(0,1)),
zaxis = list(range = range(zz)),
aspectratio = list(x = 2, y = 1, z = 0.4))
)
导致该图像出现相同的问题: