[英]Python Plotly xaxis hover text disappears when hoverinfo is set in a trace
[英]Plotly: Trace Name Appears Outside of HoverInfo
下面是一些代碼示例,其中名稱出現在 hoverinfo label 的外部。
在我的實際代碼中,我已經考慮了 hoverinfo 中的名稱,所以我只想讓這個位消失(見下圖中突出顯示的部分)。
不幸的是,我無法設置name =""
因為我使用 name 值來更改標記的顏色。
有沒有人能幫忙解決這個問題,或者以前有過嘗試這樣做的經驗? 任何幫助將不勝感激。
這很奇怪,因為這顯示在此頁面上的 plotly dash 官方文檔上發生。
category = "a"
from plotly.subplots import make_subplots
fig_ex = make_subplots(rows=1, cols=2)
fig_ex.add_scatter(y=[4, 2, 3.5], mode="markers",
marker=dict(size=20, color="MediumPurple"),
name="a", row=1, col=1)
fig_ex.add_bar(y=[2, 1, 3],
marker=dict(color="MediumPurple"),
name="b", row=1, col=1)
fig_ex.add_scatter(y=[2, 3.5, 4], mode="markers",
marker=dict(size=20, color="MediumPurple"),
name="c", row=1, col=2)
fig_ex.add_bar(y=[1, 3, 2],
marker=dict(color="MediumPurple"),
name="d", row=1, col=2)
fig_ex.update_layout(showlegend = False)
fig_ex.update_traces(hovertemplate =
"x: %{x}<br>" +
"y: %{y}")
fig_ex.for_each_trace(
lambda trace: trace.update(marker_color="LightSeaGreen") if trace.name == category else (),
)
fig_ex.show()
嘗試在hovertemplate
定義的末尾添加<extra></extra>
。 如Plotly 文檔中所述,這應該刪除跟蹤名稱。
fig_ex.update_traces(hovertemplate = "x: %{x} <br> y: %{y} <extra></extra>")
您還可以傳遞hoverlabel = {'namelength': -1}
,如此處所述以及此處JavaScript所暗示的那樣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.