I am attempting to add the absolute value of y to a plotly bar hovertemplate and have not come up with a solution or located documentation explaining how to do it. Is this possible?
here is a sampling of my data file
Dept, Pct Kept, Pct NS, Pct Canc
Main Site, 0.515625, -0.46875, -0.015625
Podiatry, 0.515151515, -0.424242424, -0.060606061
Eye Care ,0.5, -0.4, -0.1
Pediatrics, 0.636363636, -0.340909091, -0.022727273
West , 0.416666667, -0.333333333, -0.25
OAS, 0.555555556, -0.296296296, -0.148148148
OB/GYN, 0.65625, -0.28125, -0.0625
W School, 0.5, -0.166666667, -0.333333333
IFS, 0.707317073, -0.146341463, -0.146341463
Adult , 0.79, -0.14, -0.07
East , 0.777777778, -0.111111111, -0.111111111
Radiology, 0.892857143, -0.107142857, 0
P School, 1, 0, 0
here is my code. again the exercise is to create a stacked bar consisting of positive and negative numbers. the goal is to have all y values appear as positive numbers in fig.update_traces(hovertemplate=%{y:.0%}).
fig = px.bar(df, x=‘Dept’, y=[‘Pct Kept’, ‘Pct Canc’, ‘Pct NS’],
color_discrete_sequence=px.colors.qualitative.Set3,
color_discrete_map={‘Pct Kept’: ‘rgb(141,211,199)’,
‘Pct Canc’: ‘rgb(255,255,179)’,
‘Pct NS’: ‘rgb(251,128,114)’},
hover_data={‘Dept’:False},
hover_name=‘Dept’)
fig.update_traces(hovertemplate=’%{y:.0%}’) #
fig.update_layout(legend=dict(orientation=“h”, yanchor=“bottom”, y=1.02, xanchor=“right”, x=1),
legend_title_text=’ ‘,
hovermode=‘x unified’)
fig.update_yaxes(showticklabels=False, title=’ ',)
fig.show()
view of output. when i hover over the bars, would like the value of the yellow and red bars to be positive.
thanks in advance.