Skip to main contentSkip to solution

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.

Keyboard Shortcuts

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