python plotly fig.update traces - show only text if value is greather than

Viewed 896

i already spend hours searching looking for a solution to show text and percent depending of the percent value. if the value is less than 10% i only want to show text, and if the value is below 5% i want to show nothing.

this is a example code:

import plotly.express as px
df = px.data.gapminder().query("year == 2007").query("continent == 'Americas'")
fig = px.pie(df, values='pop', names='country',
             title='Population of American continent',
             hover_data=['lifeExp'], labels={'lifeExp':'life expectancy'})
fig.update_traces(textposition='inside', textinfo='percent+label')
fig.show()

may the solution is to include a list or dict (https://plotly.com/python/reference/pie/#pie-textposition) but i have no idea how. thanks for help

0 Answers
Related