When plotting a pie chart with plt.pie(), which keyword argument allows for the display of percentage values inside the slices?
When plotting a pie chart with plt.pie(), which keyword argument allows for the display of percentage values inside the slices?
Solution
The keyword argument is autopct. It takes a format string (or a function) that Matplotlib applies to each slice's percentage, and the result is printed inside the slice. For example, plt.pie(sizes, autopct="%.2f") shows values like 25.00 on a slice.
Option 3: the format string "%1.1f%%" is a valid one, but show_percentage is not a plt.pie() argument. The keyword must be autopct.
Options 1 and 4: percent and percentage do not exist in plt.pie().
To show the % sign as well, write %% in the format string, as in autopct="%1.1f%%".
Related questions:
2026: 20 May Shift 1
2026: 24 May Shift 1
2025: 21 May Shift 1