How can you display percentage values inside a pie chart in Matplotlib?
How can you display percentage values inside a pie chart in Matplotlib?
Solution
✅ Correct Option: 1
The autopct argument of plt.pie() takes a format string (or a function) and uses it to write each slice's percentage on the slice. For example, plt.pie(sizes, autopct="%1.1f%%") shows values like 25.0%.
In the format string, %1.1f shows the number with one decimal place, and %% prints a literal percent sign.
Options 2 and 3: show_labels and percentage are not arguments of plt.pie(). The real labels argument only sets the slice names, not the percentages.
Related questions:
2025: 16 May Shift 1
2026: 26 May Shift 1
2026: 31 May Shift 1
2025: 27 May Shift 2