How to specify camera perspective of 3d plotly chart in R?

烂漫一生 提交于 2019-12-30 23:14:14

问题


I would like to change the default camera perspective of my plotly 3d scatter plot, it is not clear from the help how this should be done. I understand the layout parameters should be included in a named list but cannot get it to work for the 'eye' 'up' and 'center' camera parameters.

https://plot.ly/r/reference/#layout-scene-camera

It should be something like:

require(plotly)

scene=list(bgcolor='#990055',camera=list(eye=c(1,2,3)))

plot_ly(x=rnorm(100), y=rnorm(100), z=rnorm(100),
         type="scatter3d", mode='markers+lines') %>%  layout(scene=scene)

回答1:


This is a little late but hopefully this helps others looking for a solution to this. Here's an example:

library(plotly)
set.seed(123)

# Create Random Data
ds <- diamonds[sample(1:nrow(diamonds), size = 1000),]

scene = list(camera = list(eye = list(x = -1.25, y = 1.25, z = 1.25)))

plot_ly(ds, x = carat, y = cut, z = price, group = color, type = "scatter3d", mode = "markers",
        marker = list(opacity = 0.6, size = 4)) %>% 
  layout(title = "3D Scatter plot", scene = scene)



回答2:


In python, I set the default camera like so:

scene=dict(cameraposition=[[-0.1, 0.5, -0.7, -0.2], [0.0, 0, 0.0], 2.8])

The first 4 numbers are rotation, the next 3 are x,y,z translation, and the final number is zoom. It was hard for me to find documentation as well; this was the best I found: https://plot.ly/python/3d-plots-tutorial/#in-[7]



来源:https://stackoverflow.com/questions/34178381/how-to-specify-camera-perspective-of-3d-plotly-chart-in-r

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