Question:medium

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

The Correct Option is A

Solution and Explanation


Step 1: Understanding the Concept:

The ‘autopct‘ parameter in Matplotlib's ‘pie()‘ function allows for the automatic labeling of slices with their numeric percentage values using a string formatting format.

Step 2: Detailed Explanation:

- The string ‘"%1.1f%%"‘ is a Python format specifier.
- ‘1.1f‘ indicates a floating-point number with one decimal place.
- The double ‘%%‘ is used to escape the percentage sign, as a single ‘%‘ is reserved for the format specifier.

Step 3: Final Answer:

The correct method is using the ‘autopct‘ argument.
Was this answer helpful?
0


Questions Asked in CUET (UG) exam