Autorange setup in 3D surface plot

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). Here is an example of what I have:

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))
))
And the plot generated looks like this:

If I set the range of zaxis to (1:20), then the scale is messed up and the surface is still in a cube, which I don’t want to have.

You should try using scene.aspectratio.

Thanks for the suggestion. I did try adding aspectratio = list(x=1, y=1, z=0.1) to layout() (while aspectmode = ‘manual’) but it didn’t change anything.

we need to add the above in scene not layout.

1 Like

Yup- I added scene = list(aspectmode = ‘manual’, aspectratio = list(x=1, y=1, z=0.05)) to layout() and it worked! Thank you Etienne!

1 Like