tl;dr
# β
hovertemplate works in px.bar
px.bar(df, x='date', y='value', color='var').update_traces(hovertemplate='%{value}')
# β hovertemplate doesn't work in px.scatter
px.scatter(df, x='date', y='value', color='var').update_traces(hovertemplate='%{value}')
# β hovertemplate doesn't work in px.area
px.area(df, x='date', y='value', color='var').update_traces(hovertemplate='%{value}')
Example data
df = pd.DataFrame([
{'date': '2022-01', 'var': 'A', 'value': 100},
{'date': '2022-01', 'var': 'B', 'value': 50},
{'date': '2022-01', 'var': 'C', 'value': 20},
{'date': '2022-02', 'var': 'A', 'value': 100},
{'date': '2022-02', 'var': 'B', 'value': 50},
{'date': '2022-02', 'var': 'C', 'value': 20},
{'date': '2022-03', 'var': 'A', 'value': 100},
{'date': '2022-03', 'var': 'B', 'value': 50},
{'date': '2022-03', 'var': 'C', 'value': 20},
])
hovertemplate
works in px.bar
px.bar(df, x='date', y='value', color='var').update_traces(hovertemplate='%{value}')
Note the β50 Bβ hovertext, as expected .
hovertemplate
doesnβt work in px.scatter
hovertemplate
is displayed literally (%{value}
), instead of getting values interpolated:
px.scatter(df, x='date', y='value', color='var').update_traces(hovertemplate='%{value}')
Note the %{value}
hovertext
hovertemplate
doesnβt work in px.area
Similar issue with px.area
(which compiles to "type": "scatter"
, afaict):
px.area(df, x='date', y='value', color='var').update_traces(hovertemplate='%{value}')
Note the %{value}
hovertext