通过custom_data/hovertemplate范例在plotly中创建自定义气垫卡时,颜色显示在它的右侧。例如,这里在"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]}")

(可通过here访问colab笔记本电脑)
发布于 2021-10-04 04:39:27
悬停模板包含一个辅助框,其中显示跟踪的名称。您可以通过在悬停模板中包含文本<extra></extra>来执行hide it completely。
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()

https://stackoverflow.com/questions/69430653
复制相似问题