0
0
Matplotlibdata~10 mins

Exploding slices 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 create a pie chart with one slice exploded.

Matplotlib
import matplotlib.pyplot as plt
sizes = [30, 20, 50]
explode = [[1], 0, 0]
plt.pie(sizes, explode=explode)
plt.show()
Drag options to blanks, or click blank then click option'
A1
B0.1
CTrue
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using True instead of a float value.
Using 1 which explodes the slice too far.
Using None which causes an error.
2fill in blank
medium

Complete the code to explode the second slice in the pie chart.

Matplotlib
import matplotlib.pyplot as plt
sizes = [10, 40, 50]
explode = [0, [1], 0]
plt.pie(sizes, explode=explode)
plt.show()
Drag options to blanks, or click blank then click option'
A0.2
B0
C1
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 which does not explode the slice.
Using True which is not a valid float.
Using 1 which explodes the slice too far.
3fill in blank
hard

Fix the error in the explode list to correctly explode the third slice.

Matplotlib
import matplotlib.pyplot as plt
sizes = [25, 25, 50]
explode = [0, 0, [1]]
plt.pie(sizes, explode=explode)
plt.show()
Drag options to blanks, or click blank then click option'
ATrue
B'0.3'
C0.3
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string like '0.3' which causes a type error.
Using True which is not a valid float.
Using None which causes an error.
4fill in blank
hard

Fill both blanks to explode the first and third slices in the pie chart.

Matplotlib
import matplotlib.pyplot as plt
sizes = [15, 35, 50]
explode = [[1], 0, [2]]
plt.pie(sizes, explode=explode)
plt.show()
Drag options to blanks, or click blank then click option'
A0.15
B0
C0.25
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 which does not explode the slice.
Using 1 which explodes the slice too far.
5fill in blank
hard

Fill all three blanks to explode the first and third slices and set labels for the pie chart.

Matplotlib
import matplotlib.pyplot as plt
sizes = [20, 30, 50]
labels = [[1], 'B', [2]]
explode = [[3], 0, 0]
plt.pie(sizes, labels=labels, explode=explode)
plt.show()
Drag options to blanks, or click blank then click option'
A'A'
B'C'
C0.1
D'D'
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers instead of strings for labels.
Not exploding any slice by using 0.
Using incorrect label names.