Question:

How can you display percentage values inside a pie chart in Matplotlib?

Show Hint

The "1.1f" in "%1.1f%%" formats the number as a float with 1 digit after the decimal point.
To show no decimal digits (e.g. 25% instead of 25.0%), use "%1.0f%%".
Updated On: Jun 11, 2026
  • Use the autopct="%1.1f%%" argument in plt.pie()
  • Enable show_labels=True in plt.pie()
  • Add percentage="on" inside plt.pie()
  • It is not possible to display percentages inside slices
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is A

Solution and Explanation




Step 1: Understanding the Question:

The question asks for the correct Matplotlib keyword argument used to calculate and format the percentages shown inside each wedge of a pie chart.



Step 2: Key Formula or Approach:

In Matplotlib, the plt.pie() function has an argument called autopct (automatic percentage formatting).
This argument accepts a string formatter or a function that calculates and styles the numerical value on the plot.
The format string "%1.1f%%" indicates that the percentage should be displayed as a floating-point number with one decimal place.



Step 3: Detailed Explanation:

Let us examine the options:
- Option (A) is correct. The argument autopct="%1.1f%%" tells Matplotlib to auto-calculate percentages and print them using string formatting. The double percentage signs %% are used to escape and display a literal '%' symbol on the chart.
- Option (B), show_labels=True, does not exist in plt.pie(). Labels are passed using the labels parameter.
- Option (C), percentage="on", is a non-existent parameter.
- Option (D) is incorrect because Matplotlib fully supports showing percentages inside the slices.
Thus, option (A) is the only valid, correct choice.



Step 4: Final Answer:

The correct parameter to display percentages is autopct="%1.1f%%", represented by option (A).
Was this answer helpful?
0
0