plotly 3d 表面 - 将立方体更改为矩形空间 [英] plotly 3d surface - change cube to rectangular space
问题描述
我想要一个不在立方体中的 3d 图,因为我的 z 数据比 x 和 y 轴的比例小 10 倍.你如何设置它以便 3d 绘图不是在立方体中,而是在矩形中?(我希望 x、y、z 轴也处于相同的比例.也就是说,x 和 y 是从 0 到 100,而在这个例子中,z 是从 0 到 10:)
I would like to have a 3d plot that is not in a cube, since my z data is 10 times smaller than the scale of x and y axis. How do you set it up so that the 3d plot is not in a cube, but in a rectangular shape instead? (I would like x, y, z axis to be on the same scale as well. That is, x and y are from 0 to 100, while z is from 0 to 10 in this example:)
zz = matrix(c(1:10), nrow = 100, ncol = 100)
plot_ly(z=zz, x = c(1:100), y = c(1:100), type = 'surface') %>%
layout(autorange = F, aspectmode = 'manual',
scene = list(xaxis = list(range = c(0,100)),
yaxis = list(range = c(0,100)),
zaxis = list(range = c(0,20))
))
如果我将 zaxis 的范围设置为 (1:20),那么比例会混乱并且表面仍然处于立方空间中,这是我不想要的.
If I set the range of zaxis to (1:20), then the scale is messed up and the surface is still in a cubic space, which I don't want to have.
推荐答案
你必须设置纵横比选项.
plot_ly(z=zz, x = c(1:100), y = c(1:100), type = 'surface') %>%
layout(
autorange = F,
aspectmode = 'manual',
scene = list(
zaxis = list(range = c(0,20)),
aspectratio = list(x = 1, y = 1, z = 0.2)
)
)
这篇关于plotly 3d 表面 - 将立方体更改为矩形空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!