0
0
Matplotlibdata~10 mins

Pie chart color customization in Matplotlib - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the colors of the pie chart slices.

Matplotlib
import matplotlib.pyplot as plt
sizes = [15, 30, 45, 10]
colors = [1]
plt.pie(sizes, colors=colors)
plt.show()
Drag options to blanks, or click blank then click option'
A['red', 'blue', 'green', 'yellow']
B['circle', 'square', 'triangle', 'star']
C[15, 30, 45, 10]
D['apple', 'banana', 'cherry', 'date']
Attempts:
3 left
💡 Hint
Common Mistakes
Using shapes or numbers instead of color names.
Passing the sizes list as colors.
2fill in blank
medium

Complete the code to add labels and set custom colors for the pie chart.

Matplotlib
import matplotlib.pyplot as plt
sizes = [20, 25, 35, 20]
labels = ['A', 'B', 'C', 'D']
colors = [1]
plt.pie(sizes, labels=labels, colors=colors)
plt.show()
Drag options to blanks, or click blank then click option'
A['circle', 'square', 'triangle', 'star']
B['cyan', 'magenta', 'yellow', 'black']
C['red', 'green', 'blue']
D[20, 25, 35, 20]
Attempts:
3 left
💡 Hint
Common Mistakes
Using fewer colors than slices.
Using invalid color names or shapes.
3fill in blank
hard

Fix the error in the code to correctly set the pie chart colors.

Matplotlib
import matplotlib.pyplot as plt
sizes = [10, 40, 30, 20]
colors = ['red', 'blue', 'green']
plt.pie(sizes, colors=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A['red', 'blue', 'green', 'yellow']
Bsizes
Ccolors
D['red', 'blue']
Attempts:
3 left
💡 Hint
Common Mistakes
Using a colors list shorter than sizes list.
Passing sizes as colors.
4fill in blank
hard

Fill both blanks to create a pie chart with exploded slices and custom colors.

Matplotlib
import matplotlib.pyplot as plt
sizes = [25, 35, 20, 20]
colors = [1]
explode = [2]
plt.pie(sizes, colors=colors, explode=explode)
plt.show()
Drag options to blanks, or click blank then click option'
A['gold', 'lightcoral', 'lightskyblue', 'yellowgreen']
B[0.1, 0, 0, 0]
C['red', 'blue', 'green', 'yellow']
D[1, 1, 1, 1]
Attempts:
3 left
💡 Hint
Common Mistakes
Using explode values outside 0 to 1 range.
Mismatch between colors and sizes length.
5fill in blank
hard

Fill all three blanks to create a pie chart with labels, custom colors, and exploded slices.

Matplotlib
import matplotlib.pyplot as plt
sizes = [30, 20, 25, 25]
labels = [1]
colors = [2]
explode = [3]
plt.pie(sizes, labels=labels, colors=colors, explode=explode)
plt.show()
Drag options to blanks, or click blank then click option'
A['Apples', 'Bananas', 'Cherries', 'Dates']
B['#ff9999', '#66b3ff', '#99ff99', '#ffcc99']
C[0, 0.1, 0, 0]
D['red', 'blue', 'green']
Attempts:
3 left
💡 Hint
Common Mistakes
Using fewer colors than slices.
Exploding all slices instead of one.