Complete the code to add percentage labels to the pie chart.
import matplotlib.pyplot as plt sizes = [30, 45, 25] labels = ['A', 'B', 'C'] plt.pie(sizes, labels=labels, autopct=[1]) plt.show()
The autopct parameter formats the percentage labels. '%.1f%%' shows one decimal place.
Complete the code to display percentage labels with one decimal place on the pie chart.
import matplotlib.pyplot as plt sizes = [10, 20, 70] labels = ['X', 'Y', 'Z'] plt.pie(sizes, labels=labels, autopct=[1]) plt.show()
Using '%.1f%%' formats the percentage with one decimal place, which is clear and common for pie charts.
Fix the error in the code to correctly show percentage labels on the pie chart.
import matplotlib.pyplot as plt sizes = [40, 35, 25] labels = ['Red', 'Blue', 'Green'] plt.pie(sizes, labels=labels, autopct=[1]) plt.show()
The correct format string is '%.1f%%'. It shows one decimal place and includes the percent sign properly escaped.
Fill both blanks to create a pie chart with percentage labels showing two decimals and a shadow effect.
import matplotlib.pyplot as plt sizes = [50, 30, 20] labels = ['Apple', 'Banana', 'Cherry'] plt.pie(sizes, labels=[1], autopct=[2], shadow=True) plt.show()
Use the list of labels for the labels parameter and '%.2f%%' to show percentages with two decimals.
Fill all three blanks to create a pie chart with exploded slices, percentage labels with no decimals, and a start angle of 90 degrees.
import matplotlib.pyplot as plt sizes = [15, 25, 60] labels = ['Cat', 'Dog', 'Rabbit'] explode = ([1], [2], [3]) plt.pie(sizes, labels=labels, autopct='%d%%', explode=explode, startangle=90) plt.show()
The explode tuple controls how far each slice is separated. Here, the first slice is exploded by 0.3, the second not exploded (0), and the third by 0.1.