0
0
Matplotlibdata~20 mins

Exploding slices in Matplotlib - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Exploding Slices Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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()
AA pie chart with all slices exploded equally and percentages shown.
BA pie chart with slice 'A' exploded and no percentages shown.
CA pie chart with slice 'B' slightly separated from the rest, showing percentages for all slices.
DA pie chart with slice 'D' exploded and no labels shown.
Attempts:
2 left
💡 Hint
Look at the explode tuple and which slice it affects.
data_output
intermediate
1: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)
A2
B1
C3
D0
Attempts:
2 left
💡 Hint
Count the non-zero values in the explode tuple.
🔧 Debug
advanced
1: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()
ATypeError: explode must be a list
BValueError: 'explode' must be same length as 'sizes'
CNo error, pie chart plots correctly
DIndexError: tuple index out of range
Attempts:
2 left
💡 Hint
Check if explode length matches sizes length.
🚀 Application
advanced
1: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?
A(0.1, 0, 0, 0.2)
B(0.1, 0.2, 0, 0)
C(0, 0.1, 0, 0.2)
D(0.2, 0, 0, 0.1)
Attempts:
2 left
💡 Hint
The explode tuple order matches the slice order.
🧠 Conceptual
expert
2: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?
AThe slice is not exploded at all.
BMatplotlib raises a ValueError for invalid explode value.
CThe explode value is automatically capped at 1.
DThe slice is pushed far outside the pie, possibly outside the figure area.
Attempts:
2 left
💡 Hint
Explode controls the fraction of radius to offset the slice.