简体   繁体   中英

Dash Plotly transform into an absolute value for hovertemplate

For my Dash Plotly graph, I want to remove the negative sign in my graph hover label. How do I make it into an abs value? And what is this text formatting called? Official documentation is appreciated!

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

在此处输入图片说明

  • you can use meta to hold the absolute value
  • then use meta in the hovertemplate
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")

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM