0
0
Matplotlibdata~10 mins

Box plot with plt.boxplot 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 box plot of the data list using matplotlib.

Matplotlib
import matplotlib.pyplot as plt

data = [7, 8, 5, 6, 9, 10, 4]
plt.[1](data)
plt.show()
Drag options to blanks, or click blank then click option'
Ascatter
Bhist
Cboxplot
Dplot
Attempts:
3 left
💡 Hint
Common Mistakes
Using plt.plot() instead of plt.boxplot()
Using plt.hist() which creates a histogram, not a box plot
2fill in blank
medium

Complete the code to add a title 'My Box Plot' to the plot.

Matplotlib
import matplotlib.pyplot as plt

data = [3, 5, 7, 9, 11]
plt.boxplot(data)
plt.[1]('My Box Plot')
plt.show()
Drag options to blanks, or click blank then click option'
Atitle
Bylabel
Cxlabel
Dlegend
Attempts:
3 left
💡 Hint
Common Mistakes
Using plt.xlabel() or plt.ylabel() which label axes, not the title
Using plt.legend() which adds a legend, not a title
3fill in blank
hard

Fix the error in the code to correctly display the box plot for multiple data sets.

Matplotlib
import matplotlib.pyplot as plt

data1 = [1, 2, 3, 4, 5]
data2 = [2, 3, 4, 5, 6]
plt.boxplot([1])
plt.show()
Drag options to blanks, or click blank then click option'
Adata1
B[data1, data2]
Cdata1 + data2
Ddata1, data2
Attempts:
3 left
💡 Hint
Common Mistakes
Passing data1 and data2 separated by comma without brackets
Adding the two lists which merges data instead of separate boxes
4fill in blank
hard

Fill both blanks to create a box plot with custom labels for two data sets.

Matplotlib
import matplotlib.pyplot as plt

data1 = [10, 20, 30]
data2 = [15, 25, 35]
plt.boxplot([data1, data2], labels=[1])
plt.[2]('Custom Box Plot')
plt.show()
Drag options to blanks, or click blank then click option'
A['Set A', 'Set B']
B['Data1', 'Data2']
Ctitle
Dxlabel
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect label format like a string instead of list
Using plt.xlabel() instead of plt.title() for the plot title
5fill in blank
hard

Fill all three blanks to create a box plot with notch style, custom labels, and a y-axis label.

Matplotlib
import matplotlib.pyplot as plt

data1 = [5, 7, 9]
data2 = [6, 8, 10]
plt.boxplot([data1, data2], [1]=True, labels=[2])
plt.[3]('Values')
plt.show()
Drag options to blanks, or click blank then click option'
Anotch
B['Group 1', 'Group 2']
Cylabel
Dxlabel
Attempts:
3 left
💡 Hint
Common Mistakes
Using plt.xlabel() instead of plt.ylabel() for y-axis label
Not passing labels as a list
Forgetting to set notch=True for notch style