簡體   English   中英

如何使用場景向 scatter3D Plotly plot 添加注釋?

[英]How to add annotations to a scatter3D Plotly plot using scene?

我正在嘗試向具有不同場景的 scatter3d Plotly plot 中的點添加文本注釋。 如何使注釋隨 plot 移動? 即使我將外部參照和 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

如果您的問題允許您從布局中的注釋切換到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))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM