Challenge - 5 Problems
Donut Chart Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a simple donut chart code
What will be the output of this code snippet that creates a donut chart using matplotlib?
Matplotlib
import matplotlib.pyplot as plt sizes = [30, 20, 50] labels = ['A', 'B', 'C'] plt.pie(sizes, labels=labels, wedgeprops=dict(width=0.4)) plt.show()
Attempts:
2 left
💡 Hint
Look at the wedgeprops argument and what width controls in a pie chart.
✗ Incorrect
The wedgeprops argument with width less than 1 creates a donut chart by making a hole in the center of the pie chart.
❓ data_output
intermediate1:30remaining
Number of wedges in a donut chart
Given this code, how many wedges (slices) will the donut chart display?
Matplotlib
import matplotlib.pyplot as plt sizes = [10, 15, 25, 50] labels = ['W', 'X', 'Y', 'Z'] plt.pie(sizes, labels=labels, wedgeprops=dict(width=0.3)) plt.show()
Attempts:
2 left
💡 Hint
Count the number of elements in the sizes list.
✗ Incorrect
Each element in sizes corresponds to one wedge in the pie or donut chart.
❓ visualization
advanced2:30remaining
Effect of changing width in donut chart
What visual difference will you see if you change the width in wedgeprops from 0.5 to 0.9 in this donut chart code?
Matplotlib
import matplotlib.pyplot as plt sizes = [40, 30, 30] labels = ['Red', 'Green', 'Blue'] plt.pie(sizes, labels=labels, wedgeprops=dict(width=0.5)) plt.show()
Attempts:
2 left
💡 Hint
Width controls the thickness of the donut ring; higher width means thicker ring.
✗ Incorrect
Increasing width closer to 1 increases the thickness of the donut ring, making the hole smaller.
🔧 Debug
advanced2:00remaining
Identify the error in donut chart code
What error will this code raise when trying to create a donut chart?
Matplotlib
import matplotlib.pyplot as plt sizes = [25, 25, 25, 25] labels = ['Q1', 'Q2', 'Q3', 'Q4'] plt.pie(sizes, labels=labels, wedgeprops={'width': 1.2}) plt.show()
Attempts:
2 left
💡 Hint
Width controls the thickness of the donut ring and must be between 0 and 1.
✗ Incorrect
Width greater than 1 is invalid and causes a ValueError in matplotlib pie charts.
🚀 Application
expert3:00remaining
Customize donut chart with exploded slice
Which code snippet correctly creates a donut chart with the second slice exploded outward?
Attempts:
2 left
💡 Hint
The explode list controls how far each slice is offset; the second slice is index 1.
✗ Incorrect
To explode the second slice, only the second value in explode should be non-zero.