0
0
Matplotlibdata~20 mins

Pie chart color customization in Matplotlib - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Pie Chart Color Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
What colors will the pie chart slices have?
Consider this code that creates a pie chart with custom colors. What colors will the slices be?
Matplotlib
import matplotlib.pyplot as plt
sizes = [30, 20, 50]
colors = ['red', 'green', 'blue']
plt.pie(sizes, colors=colors)
plt.show()
ASlices colored all gray
BSlices colored default matplotlib colors ignoring the list
CSlices colored red, green, and blue respectively
DSlices colored yellow, cyan, and magenta
Attempts:
2 left
💡 Hint
The colors list is passed to the pie function to set slice colors.
data_output
intermediate
1:30remaining
How many slices will be colored orange?
Given this pie chart code, how many slices will be orange?
Matplotlib
import matplotlib.pyplot as plt
sizes = [10, 20, 30, 40]
colors = ['orange', 'orange', 'blue', 'green']
plt.pie(sizes, colors=colors)
plt.show()
A2 slices
B1 slice
C3 slices
D0 slices
Attempts:
2 left
💡 Hint
Count how many times 'orange' appears in the colors list.
🔧 Debug
advanced
2:00remaining
Why does this pie chart ignore the colors list?
This code tries to color slices but all slices appear gray. What is the error?
Matplotlib
import matplotlib.pyplot as plt
sizes = [25, 25, 25, 25]
colors = ['red', 'green', 'blue', 'yellow']
plt.pie(sizes, color=colors)
plt.show()
AThe pie function does not accept a colors parameter
BThe sizes list must be strings, not integers
CThe colors list must have hex codes, not names
DThe parameter should be 'colors', not 'color'
Attempts:
2 left
💡 Hint
Check the exact parameter name for slice colors in plt.pie.
visualization
advanced
2:00remaining
Which option shows a pie chart with a custom color palette?
You want a pie chart with slices colored purple, orange, and teal. Which code produces this?
Aplt.pie([40, 30, 30], colors=['purple', 'orange', 'teal'])
Bplt.pie([40, 30, 30], color=['purple', 'orange', 'teal'])
Cplt.pie([40, 30, 30], colors=['red', 'green', 'blue'])
Dplt.pie([40, 30, 30], colors=['purple', 'orange'])
Attempts:
2 left
💡 Hint
Use the correct parameter name and provide one color per slice.
🚀 Application
expert
3:00remaining
How to create a pie chart with alternating slice colors?
You want a pie chart with 6 slices where colors alternate between 'red' and 'blue'. Which code creates this pattern?
A
colors = ['red', 'blue'] * 3
plt.pie([10]*6, color=colors)
plt.show()
B
colors = ['red' if i % 2 == 0 else 'blue' for i in range(6)]
plt.pie([10]*6, colors=colors)
plt.show()
C
colors = ['red', 'blue', 'red', 'blue', 'red', 'blue']
plt.pie([10]*6, colors=colors)
plt.show()
D
colors = ['red', 'blue']
plt.pie([10]*6, colors=colors)
plt.show()
Attempts:
2 left
💡 Hint
Use a list comprehension to generate the alternating colors list.