Challenge - 5 Problems
Exploding Slices Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of pie chart with exploding slices
What will be the output of this code snippet that creates a pie chart with one slice exploded?
Matplotlib
import matplotlib.pyplot as plt sizes = [15, 30, 45, 10] labels = ['A', 'B', 'C', 'D'] explode = (0, 0.1, 0, 0) # only 'B' is exploded plt.pie(sizes, labels=labels, explode=explode, autopct='%1.1f%%') plt.show()
Attempts:
2 left
💡 Hint
Look at the explode tuple and which slice it affects.
✗ Incorrect
The explode tuple has 0.1 only for the second slice 'B', so only that slice is separated. autopct shows percentages for all slices.
❓ data_output
intermediate1:00remaining
Number of exploded slices in pie chart
Given the explode parameter below, how many slices will be exploded in the pie chart?
Matplotlib
explode = (0.2, 0, 0.3, 0, 0)
Attempts:
2 left
💡 Hint
Count the non-zero values in the explode tuple.
✗ Incorrect
The explode tuple has two non-zero values: 0.2 and 0.3, so two slices will be exploded.
🔧 Debug
advanced1:30remaining
Identify the error in pie chart explode parameter
What error will this code raise when trying to plot a pie chart with explode parameter?
Matplotlib
import matplotlib.pyplot as plt sizes = [20, 30, 25] labels = ['X', 'Y', 'Z'] explode = (0.1, 0.2) # length mismatch plt.pie(sizes, labels=labels, explode=explode) plt.show()
Attempts:
2 left
💡 Hint
Check if explode length matches sizes length.
✗ Incorrect
The explode tuple length is 2 but sizes length is 3, causing a ValueError about length mismatch.
🚀 Application
advanced1:30remaining
Creating a pie chart with multiple exploded slices
You want to create a pie chart with 4 slices where the first and last slices are exploded by 0.1 and 0.2 respectively. Which explode tuple should you use?
Attempts:
2 left
💡 Hint
The explode tuple order matches the slice order.
✗ Incorrect
The first slice corresponds to the first explode value (0.1), and the last slice corresponds to the last explode value (0.2).
🧠 Conceptual
expert2:00remaining
Effect of explode values greater than 1 in pie chart
What happens if you set an explode value greater than 1 for a slice in a matplotlib pie chart?
Attempts:
2 left
💡 Hint
Explode controls the fraction of radius to offset the slice.
✗ Incorrect
Explode values represent fraction of the radius to offset the slice. Values greater than 1 push the slice far outside the pie, possibly outside the visible area.