Decimal precision in pie charts

Hi! I’m new to Plotly. I’ve created a pie chart and having trouble with writing the precision formatting syntax. I’ve referenced the Figure reference documentation but wasn’t able to successfully execute the suggested syntax. I’m presenting percentages as text in the chart but looking to limit the percentages to one decimal point. For example, a slice has text of 6.47% but want to have the chart show 6.5%. Any assistance that can be provided will be greatly appreciated. Thanks!

Welcome @woodaaro21 :-). Here you could use a text template as described in https://plot.ly/python/text-and-annotations/#customize-displayed-text-with-a-text-template. For example you could have %{percent:.1f} in the text template to keep only one decimal number.

Thanks Emmanuelle for your response! With your feedback and altering the syntax numerous times, I was able to figure it out. The syntax I used is: texttemplate=’%{percent:.1%f}’. I just put a “%” after the .1 and it worked! Thanks for your guidance!

1 Like

Hello, I tried the following code to Round values in pie chart for plotly it round the values in pie chart to 0.1 decimal value and it worked!!

fig.update_traces(texttemplate=’%{percent:.1%f}’)

1 Like

Hello, based on this answer, the only solution which worked for me was "%{percent:.0%}", i.e. leaving out the f (in plotly version 5.3.1). This is correct, according to this source.