100% barchart without calculating?

Is it possible to create the same 100% bar chart without recalculating the values in advance? If I check out a label in the plot, the remaining values should add up to 100%.

import pandas as pd
import plotly.express as px
data = {‘val1’: [10, 200, 55],
‘val2’: [90, 200, 55]}
df = pd.DataFrame(data, index=[‘a’, ‘b’, ‘c’])
df= df.apply(lambda x: round(x * 100 / x.sum(), 2), axis=1)
melted_df = pd.melt(df.reset_index(), id_vars=‘index’, var_name=‘item’, value_name=‘value’)
fig = px.bar(
melted_df,
x=‘index’,
y=‘value’,
color=‘item’,
barmode=‘stack’,
title=‘100% chart’,
)
fig.show()

Hey @marvy, not much has changed in the meantime…