Skip to main contentSkip to solution

When plotting a pie chart with plt.pie(), which keyword argument allows for the display of percentage values inside the slices?

Solution

✅ Correct Option: 2

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%%".

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question