【问题标题】:Dash Plotly transform into an absolute value for hovertemplateDash Plotly 转换为 hovertemplate 的绝对值
【发布时间】:2021-07-16 08:20:50
【问题描述】:

对于我的 Dash Plotly 图表,我想删除图表悬停标签中的负号。如何将其变为 abs 值?这种文本格式叫什么?感谢官方文档!

hovertemplate="%{base:.2f}"

【问题讨论】:

    标签: python hover plotly plotly-dash


    【解决方案1】:
    • 您可以使用来保存绝对值
    • 然后在 hovertemplate 中使用 meta
    import plotly.graph_objects as go
    import pandas as pd
    import numpy as np
    
    df = pd.DataFrame({
            "x": pd.date_range("1-jan-2021", periods=10),
            "Positive": np.random.uniform(1, 5, 10),
            "Negative": np.random.uniform(-5, -3, 10),})
    
    go.Figure(
        [go.Bar(x=df["x"], y=df[t], meta=df[t].abs(), name=t, hovertemplate="%{meta:.2f}") for t in ["Positive", "Negative"]]
    ).update_layout(hovermode="x unified")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-01
      • 1970-01-01
      • 2022-07-29
      • 1970-01-01
      • 2019-06-25
      • 1970-01-01
      • 2023-03-05
      相关资源
      最近更新 更多