首页 > 解决方案 > Plotly:如何在 3D 图中为相机视图设置手动缩放?

问题描述

我使用下面的数据创建 3D 图,但无法显示完整的轴。我可以设置原始缩放以显示整个情节吗?

> dput(analysis[,c(1:3)])
structure(list(L = c(60, 70, 80, 90, 100, 110, 120, 130, 140, 
60, 70, 80, 90, 100, 110, 120, 130, 140, 60, 70, 80, 90, 100, 
110, 120, 130, 140, 60, 70, 80, 90, 100, 110, 120, 130, 140), 
    S = c(6, 6, 6, 6, 6, 6, 6, 6, 6, 7.5, 7.5, 7.5, 7.5, 7.5, 
    7.5, 7.5, 7.5, 7.5, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10.5, 10.5, 
    10.5, 10.5, 10.5, 10.5, 10.5, 10.5, 10.5), theta = c(0.387648377238727, 
    0.365065109815399, 0.361945691353903, 0.308994736435413, 
    0.31312106684787, 0.347902392899031, 0.322177548286843, 0.313365432864246, 
    0.318566760330453, 0.329343960085812, 0.4305266050694, 0.412161930763136, 
    0.405615100181224, 0.342671510183088, 0.379821799998522, 
    0.351607159033827, 0.338622255013142, 0.330437773555393, 
    0.359828622589832, 0.43564477128519, 0.446968516154636, 0.364471191945187, 
    0.311372659889749, 0.343410820556976, 0.319743944825857, 
    0.367342095248675, 0.303374120182854, 0.402025212310935, 
    0.486427167733943, 0.402463557214462, 0.380560495098558, 
    0.32606222794188, 0.383477501221339, 0.315207079133179, 0.359243336292084, 
    0.338734658604223)), class = "data.frame", row.names = c(NA, -36L))


fig <- plot_ly(analysis, x = ~L, y = ~S, z = ~theta) %>% 
  add_markers(opacity = 0.6) %>% 
  layout(scene = list(xaxis = list(title = 'Span Length (ft)'),
                     yaxis = list(title = 'Girder Spacing (ft)'),
                     zaxis = list(title = 'End Rotation (deg)')),
         margin = list(b=130), annotations = 
 list(x = 0.9, y = -0.2, text = "<i>Figure 4.  Relationship between the input variables used in the parametric study.</i>", 
      showarrow = F, xref='paper', yref='paper', 
      xanchor='right', yanchor='auto', xshift=0, yshift=0,
      font=list(size=15)))

下面是 HTML 输出的截图:

在此处输入图像描述

标签: rplotlyr-plotly

解决方案


您必须找到适合您需求的组合x, y, and zscene = list(camera = list(eye = list(x=1.5, y=3, z = 0.1)))

您的代码片段不可重现,但我们可以使用以下方法重现问题:

fig <- plot_ly(z = ~volcano)
fig <- fig %>% add_surface()
fig

在此处输入图像描述

现在,只需包括:

scene = list(camera = list(eye = list(x=1.5, y=3, z = 0.1)))
fig <- fig  %>% layout(title = "changed zoom", scene = scene)

你会得到:

在此处输入图像描述


推荐阅读