plotly 3d surface - 将立方体改为矩形空间

时间:2016-05-04 15:55:56

标签: r 3d aspect-ratio plotly

我想要一个不在立方体中的3d图,因为我的z数据比x和y轴的尺度小10倍。你如何设置它以使3d图不是在立方体中,而是在矩形形状中? (我希望x,y,z轴也能达到相同的比例。也就是说,x和y从0到100,而z在这个例子中是0到10)

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),那么比例就会变得混乱,表面仍然是一个立方体空间,我不想拥有它。

1 个答案:

答案 0 :(得分:3)

您必须设置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)
    )
  )