✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Hiding % labels in px.pie chart python

basically the same question like here, but it is for javascript

when i try textinfo None as recommended there, i get a key error

how do i hide it?

ok, i have found it. it just needs to be fig_pie.update_traces(textinfo='none'), but it hides all. now i wonder if there is a way to CODITIONALY hide the % labels.

lets say i have a pie chart like this
pie hide
and i would like to hide all that does not fit into the the pie, or i want to leave only the first ten biggest… or something like that. just whatever based on a contiditon.

how would i do that?

Hi @nirvikalpa, you can impose that the text fits inside pie sectors with textposition, and then impose a minimum font size so that labels which don’t fit won’t be displayed. This is explained in the documentation example on pie charts and uniformtext

import plotly.express as px
df = px.data.gapminder().query("continent == 'Asia'")
fig = px.pie(df, values='pop', names='country')
fig.update_traces(textposition='inside')
fig.update_layout(uniformtext_minsize=12, uniformtext_mode='hide')
fig.show()
1 Like

pretty neat trick, thank you