我正在尝试向具有不同场景的scatter3d Plotly绘图中的点添加文本注释。我怎样才能使注释随着绘图一起移动?即使我将xref和yref标记为“scene”,注释也不会移动。
这是我正在尝试运行的一个可重现的示例:
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
发布于 2019-11-05 18:34:52
如果你的问题允许你从布局中的注解切换到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))https://stackoverflow.com/questions/58612920
复制相似问题