Can you show percentage of sum of all y values over bars when y axis is absolute values?

I’m trying to make a bar chart in Plotly Express where x_axis is categories, y_axis is numeric values, like kilograms, and I want a percentage % number on top ( as in “textposition= ‘outside’”) of each bar that shows not the kilograms but the percentage of all weight. Like if you have one bar y=3kg, one bar y=2kg then they would have 60% and 40% displaying over their bars respectively.

Is that even possible? I know how to display values and “d3” format them to round them and add a ‘%’ symbol but %{y: .0%} just makes the absolute values look like percentage. I can’t find examples online for that specific thing I’m trying to do. Data source is a pandas dataframe.

Any suggestion?

1 Like