【问题标题】:Remove color to the right of custom hovercard in Plotly Express在 Plotly Express 中删除自定义悬停卡右侧的颜色
【发布时间】:2021-11-24 13:32:18
【问题描述】:

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

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 notebook可以访问here

【问题讨论】:

    标签: python plotly plotly-python plotly-express


    【解决方案1】:

    悬停模板包含一个显示跟踪名称的辅助框。您可以通过在悬停模板中包含文本<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()
    

    【讨论】:

      猜你喜欢
      • 2020-01-28
      • 1970-01-01
      • 2016-06-06
      • 2021-06-01
      • 1970-01-01
      • 2023-03-04
      • 1970-01-01
      • 2021-04-23
      • 2021-08-14
      相关资源
      最近更新 更多