i try to plot the y-axis in percent. i there a way like in excel, excel scale automacily from 0 -100% ? or it is necessary first to calculate (group by year and continent) in the dataframe?
import plotly.express as px
df = px.data.gapminder()
fig = px.area(df, x="year", y="pop", color="continent",
line_group="country")
fig.show()
thanks for helP!
try this:
import plotly.express as px
df = px.data.gapminder()
dfw = df.groupby(['continent','year'])['pop'].sum().to_frame()
dfw.reset_index(inplace=True)
fig = px.area(dfw, x="year", y="pop", color="continent", groupnorm='fraction')
fig.update_layout(yaxis_tickformat='%')
fig.show()

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With