删除 Plotly Express 中自定义悬浮卡右侧的颜色

Remove color to the right of custom hovercard in Plotly Express

通过 custom_data/hovertemplate 范例在 plotly express 中创建自定义悬浮卡片时,颜色显示在它的右侧。例如,此处显示“蓝色”就在“a=1”的右侧。如何去除“蓝色”?

import pandas as pd
import plotly.express as px

df = pd.DataFrame(dict(x=["a"], y=[1], color=["blue"], hover=["a=1"]))
fig = px.bar(df, "x", "y", "color", custom_data=["hover"])
fig.update_traces(hovertemplate="%{customdata[0]}")

(可访问colab笔记本here)

悬停模板包含一个显示跟踪名称的辅助框。您可以 hide it completely 通过在悬停模板中包含文本 <extra></extra>

import pandas as pd
import plotly.express as px

df = pd.DataFrame(dict(x=["a"], y=[1], color=["blue"], hover=["a=1"]))
fig = px.bar(df, x="x", y="y", color="color", custom_data=["hover"])
fig.update_traces(hovertemplate="%{customdata[0]}<extra></extra>")
fig.show()