简体   繁体   English

如何在R中指定三维图表的摄像机视角?

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

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

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)

In python, I set the default camera like so: 在python中,我像这样设置默认摄像头:

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. 前4个数字是旋转,接下来的3个是x,y,z平移,最后的数字是缩放。 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//plot.ly/python/3d-plots-tutorial/#in-[7]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM