plotly 3d surface - change cube to rectangular space

这一生的挚爱 提交于 2019-12-23 18:52:16

问题


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))
         ))

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.


回答1:


You have to set the aspectratio option.

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)
    )
  )


来源:https://stackoverflow.com/questions/37032687/plotly-3d-surface-change-cube-to-rectangular-space

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!