我很难让悬停文本出现在预编译的四分位数Plotly图中。本质上,我试图用它们的ID来标记异常值。
示例1:悬停文本在这里运行良好,您可以在-100点上悬停,悬停文本50显示以及标准悬停细节。
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Box(
y=[1,2,3,4,-100],
hovertext=[10, 20, 30, 40, 50],
showlegend=False
))
fig.show()示例2:问题示例--似乎无法让它在这个问题上发挥作用。一个字符串可以工作,但是元素数组不能工作。我也尝试过确保数组中的元素是字符串,但没有成功。
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(
go.Box(
y=[[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]],
name="Precompiled Quartiles",
hovertext=[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
# hovertext='Hovetext Working!!'
)
)
fig.update_traces(q1=[ 1], median=[ 4 ],
q3=[ 7 ], lowerfence=[-1],
upperfence=[5,], mean=[ 2.2])
fig.show()任何想法或想法,如何使这项工作,将不胜感激。我试着用定制数据和悬停模板来实现这一点,但也没有成功。
发布于 2022-01-22 10:08:45
看来我最终还是用了定制数据和hovertemplate来解决这个问题。解决办法如下:
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(
go.Box(
y=[[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]],
name="Precompiled Quartiles",
customdata=[[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]],
hovertemplate='Value: %{y}<br>Custom: %{customdata}',
)
)
fig.update_traces(q1=[ 1], median=[ 4 ],
q3=[ 7 ], lowerfence=[-1],
upperfence=[5,], mean=[ 2.2])
fig.show()https://stackoverflow.com/questions/70811702
复制相似问题