【问题标题】:How to add annotations to a scatter3D Plotly plot using scene?如何使用场景向 scatter3D Plotly 绘图添加注释?
【发布时间】:2020-02-25 00:25:00
【问题描述】:

我正在尝试向具有不同场景的 scatter3d Plotly 图中的点添加文本注释。如何使注释随情节移动?即使我将外部参照和 yref 签署为“场景”,注释也不会移动。

这是我正在尝试运行的可重现示例:

library(plotly)

rep.ex = data.frame(x1=1:20, y1=1:20, z1=(1:20)*2, text1=letters[1:20])

axoff <- list(title = "", zeroline = FALSE, showline = FALSE, showticklabels = FALSE, showgrid = FALSE, autotick = F)
axoffxy <- list(title = "", zeroline = FALSE, showline = FALSE, showticklabels = FALSE, showgrid = FALSE, autotick = F, showspikes=F)


plot_ly(data=data.frame(rep.ex), x=rep.ex$x1, y=rep.ex$y1, z=rep.ex$z1, 
            marker=list(size=2.6), 
            color=rep.ex$x1, hoverinfo='text',
            text=rep.ex$text1,
            type="scatter3d", mode = "markers") %>%
  layout(showlegend = T, dragmode="turntable", scene = list(aspectmode='cube', xaxis = axoffxy, yaxis = axoffxy, zaxis = axoff), 
         annotations=list(showarrow=FALSE, 
                          text='Here I insert my annotation',  
                          xref='scene',     
                          yref='scene',
                          zref='scene',
                          x=1,  
                          y=1, 
                          z=2,
                          xanchor='left',   
                          yanchor='bottom',  
                          font=list(size=12 )))

我使用的是 Plotly 4.9.0 版

【问题讨论】:

    标签: r plotly scene r-plotly scatter3d


    【解决方案1】:

    如果您的问题允许您从布局中的注释切换到add_trace,它将四处移动。像这样的东西可以解决这个问题:

    plot_ly(data=data.frame(rep.ex), x=rep.ex$x1, y=rep.ex$y1, z=rep.ex$z1, 
            marker=list(size=2.6), color=rep.ex$x1, hoverinfo='text',
            text=rep.ex$text1, type="scatter3d", mode = "markers", showlegend=F) %>%
      add_trace(type='scatter3d', mode='text', x=10,y=10,z=10, 
                text='Here I insert my annotation', showlegend=F, inherit=F) %>%
      layout(showlegend = T, dragmode="turntable", 
             scene = list(aspectmode='cube', xaxis = axoffxy, yaxis = axoffxy, zaxis = axoff))
    

    【讨论】:

    • 我想现在就可以了,我真的很喜欢箭头,它似乎在早期版本的 plotly 中有效,但现在不再有效。 (除非有人在接下来的几天内提出注释版本,否则我会标记为正确)
    • 使用了同样的方法here
    猜你喜欢
    • 1970-01-01
    • 2022-12-02
    • 1970-01-01
    • 2021-09-16
    • 2022-01-20
    • 2021-06-27
    • 2023-03-21
    • 2019-01-27
    相关资源
    最近更新 更多