0
0
Matplotlibdata~20 mins

Basic pie chart with plt.pie in Matplotlib - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Pie Chart Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this pie chart code?
Consider this Python code using matplotlib to create a pie chart. What will be the displayed percentages on the pie slices?
Matplotlib
import matplotlib.pyplot as plt
sizes = [10, 20, 30]
labels = ['A', 'B', 'C']
plt.pie(sizes, labels=labels, autopct='%1.1f%%')
plt.show()
ASlices labeled A: 16.7%, B: 33.3%, C: 50.0%
BSlices labeled A: 25%, B: 25%, C: 50%
CSlices labeled A: 10%, B: 20%, C: 30%
DSlices labeled A: 20%, B: 30%, C: 50%
Attempts:
2 left
💡 Hint
Percentages are calculated as each size divided by the total sum of sizes.
data_output
intermediate
1:30remaining
How many slices will the pie chart have?
Given this code snippet, how many slices will the pie chart display?
Matplotlib
import matplotlib.pyplot as plt
sizes = [5, 15, 25, 55]
plt.pie(sizes)
plt.show()
A1 slice
B5 slices
C3 slices
D4 slices
Attempts:
2 left
💡 Hint
Each number in sizes corresponds to one slice.
visualization
advanced
2:30remaining
Which option produces a pie chart with exploded slices?
Look at these four code snippets. Which one will create a pie chart where each slice is slightly separated (exploded) from the center?
Aplt.pie([10, 20, 30], explode=[0, 0, 0])
Bplt.pie([10, 20, 30], explode=[1, 0, 0])
Cplt.pie([10, 20, 30], explode=[0.1, 0.1, 0.1])
Dplt.pie([10, 20, 30], explode=[0.1, 0, 0.1])
Attempts:
2 left
💡 Hint
The explode parameter controls how far each slice is offset from the center.
🔧 Debug
advanced
2:00remaining
What error does this pie chart code raise?
This code tries to create a pie chart but fails. What error will it raise?
Matplotlib
import matplotlib.pyplot as plt
sizes = [10, 20]
labels = ['A', 'B', 'C']
plt.pie(sizes, labels=labels)
plt.show()
ATypeError: unsupported operand type(s) for +: 'int' and 'str'
BValueError: 'labels' must be the same length as 'sizes'
CIndexError: list index out of range
DNo error, pie chart displays with missing label
Attempts:
2 left
💡 Hint
Labels list length must match sizes list length exactly.
🚀 Application
expert
2:30remaining
Which option produces a pie chart with a shadow and start angle at 90 degrees?
You want a pie chart that has a shadow effect and starts drawing slices from the top (90 degrees). Which code snippet does this correctly?
Aplt.pie([15, 25, 60], shadow=True, startangle=90)
Bplt.pie([15, 25, 60], shadow=False, startangle=0)
Cplt.pie([15, 25, 60], shadow=True, startangle=0)
Dplt.pie([15, 25, 60], shadow=False, startangle=90)
Attempts:
2 left
💡 Hint
The shadow parameter adds a shadow, startangle rotates the start position in degrees.