Reputation: 1447
I am using Rstudio on a mac. I want to 3dplot a surface thanks to 4 points with their cartesian coordinates. When I use : plot_ly(x=x, y=y) I am able to fix the range of the axis. When using plot_ly(x=x, y=y, z=z) the same method of ranging the axis does not work anymore.
x = c(0, 1, 1, 0)
y = c(0, 0, 1, 1)
z = c(0, 1, 1, 0)
scene = list(camera = list(eye = list(x=-2.5, y=0.1, z=0.1), center=list(x=0, y=0, z=0), up=list(x=0, y=0, z=1)))
axx <- list(range=c(0, 10), showline=TRUE, linecolor=toRGB("black"))
p <- plot_ly(x = x, y = y, z = z, text = c("M0", "M1", "M2", "M3"),
type = "mesh3d",
showscale = FALSE
) %>%
layout(scene=scene, xaxis=axx, yaxis=axx, zaxis=axx )
In fine I intend to use this code to be looped on a data.frame and see the evolution of my point. And there is no point on doing that if I cannot have the same scale on each plot iteration.
for (ind in 1:datalen)
{
print(ind)
x = c(0, myCoord$az[ind], myCoord$az[ind], 0)
y = c(0, 0, 1, 1)
z = c(0, myCoord$ax[ind], myCoord$ax[ind], 0)
p <- plot_ly(x = x, y = y, z = z, text = c("M0", "M1", "M2", "M3"),
type = "mesh3d",
showscale = FALSE
) %>%
layout(scene=scene, xaxis=bxx, yaxis=bxx, zaxis=axx )
print(p)
Sys.sleep(0.5)
}
Thank you for your help.
Upvotes: 1
Views: 1168
Reputation: 298
You need to use latest version of plotly and set axis as atributes of the Scene.
For example:
layout.scene = Scene(xaxis=XAxis(title='my x label'),
yaxis=YAxis(title='my y label'),
zaxis=ZAxis(title='my z label', range=[z_min, z_max]))
Upvotes: 0