0
0
Matplotlibdata~10 mins

Basic pie chart with plt.pie 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 import the matplotlib plotting module.

Matplotlib
import [1] as plt
Drag options to blanks, or click blank then click option'
Amatplotlib.pyplot
Bpandas
Cnumpy
Dseaborn
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the wrong library like numpy or pandas.
Forgetting to import pyplot specifically.
2fill in blank
medium

Complete the code to create a pie chart from the data list.

Matplotlib
data = [30, 20, 50]
plt.[1](data)
plt.show()
Drag options to blanks, or click blank then click option'
Apie
Bbar
Cplot
Dhist
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'bar' or 'plot' instead of 'pie'.
Forgetting to call plt.show() to display the chart.
3fill in blank
hard

Fix the error in the code to label the pie chart slices.

Matplotlib
sizes = [40, 35, 25]
labels = ['A', 'B', 'C']
plt.pie(sizes, labels=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A['A', 'B', 'C']
Bsizes
CNone
Dlabels
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the sizes list instead of labels.
Passing a string literal instead of the variable.
4fill in blank
hard

Fill both blanks to create a pie chart with percentages and a title.

Matplotlib
sizes = [10, 20, 70]
labels = ['X', 'Y', 'Z']
plt.pie(sizes, labels=[1], autopct=[2])
plt.title('My Pie Chart')
plt.show()
Drag options to blanks, or click blank then click option'
Alabels
B'%1.1f%%'
C'%d%%'
Dsizes
Attempts:
3 left
💡 Hint
Common Mistakes
Passing sizes instead of labels for labels parameter.
Using incorrect format strings for autopct.
5fill in blank
hard

Fill all three blanks to create a pie chart with labels, explode effect, and shadow.

Matplotlib
sizes = [15, 30, 55]
labels = ['Red', 'Blue', 'Green']
explode = ([1], [2], [3])
plt.pie(sizes, labels=labels, explode=explode, shadow=True)
plt.show()
Drag options to blanks, or click blank then click option'
A0.1
B0
C0.2
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using integers like 1 which offset too much.
Not using a tuple for explode.