A box plot shows the distribution of data by displaying the median, quartiles, and possible outliers. It helps us understand the spread and skewness of the data.
Click to reveal answer
beginner
Which matplotlib function is used to create a box plot?
The function plt.boxplot() is used to create box plots in matplotlib.
Click to reveal answer
beginner
What does the line inside the box in a box plot represent?
The line inside the box represents the median value of the data set.
Click to reveal answer
intermediate
How does plt.boxplot show outliers in the data?
Outliers are shown as individual points outside the whiskers of the box plot.
Click to reveal answer
intermediate
What are the 'whiskers' in a box plot?
Whiskers extend from the box to the smallest and largest values within 1.5 times the interquartile range from the quartiles. They show the range of most data points.
Click to reveal answer
What does the box in a box plot represent?
AThe interquartile range (middle 50% of data)
BThe mean and standard deviation
CAll data points
DOnly outliers
✗ Incorrect
The box shows the interquartile range, which covers the middle 50% of the data.
Which matplotlib function creates a box plot?
Aplt.hist()
Bplt.scatter()
Cplt.plot()
Dplt.boxplot()
✗ Incorrect
plt.boxplot() is the function used to create box plots.
In a box plot, what do the whiskers represent?
AThe range of data excluding outliers
BThe outliers
CThe mean value
DThe median value
✗ Incorrect
Whiskers extend to the smallest and largest data points within 1.5 times the interquartile range, excluding outliers.
How are outliers shown in a box plot?
AAs whiskers
BAs individual points outside whiskers
CAs part of the box
DThey are not shown
✗ Incorrect
Outliers appear as individual points outside the whiskers.
What does the line inside the box of a box plot indicate?
AMean
BMode
CMedian
DMaximum value
✗ Incorrect
The line inside the box shows the median of the data.
Explain how to create a box plot using matplotlib's plt.boxplot and what key parts of the data it shows.
Think about the parts of the box plot and the function name.
You got /5 concepts.
Describe what information a box plot gives about a data set and why it is useful.
Consider what you learn about data from the box and whiskers.
You got /5 concepts.
Practice
(1/5)
1. What does the plt.boxplot() function primarily show about a dataset?
easy
A. The exact values of all data points
B. The spread and center of the data using quartiles
C. Only the average value of the data
D. The correlation between two variables
Solution
Step 1: Understand box plot purpose
A box plot summarizes data distribution by showing quartiles and spread.
Step 2: Identify what plt.boxplot() displays
This function creates a box plot that visualizes median, quartiles, and outliers.
Final Answer:
The spread and center of the data using quartiles -> Option B
Quick Check:
Box plot = Data spread and center [OK]
Hint: Box plots show spread and center, not individual points [OK]
Common Mistakes:
Thinking boxplot shows all data points exactly
Confusing boxplot with scatter plot
Assuming boxplot shows correlation
2. Which of the following is the correct way to create a vertical box plot of data stored in a list named data using matplotlib?
easy
A. plt.boxplot(data, orientation='horizontal')
B. plt.boxplot(data, vertical=False)
C. plt.boxplot(data, vert=True)
D. plt.boxplot(data, vert='no')
Solution
Step 1: Check parameter for vertical boxplot
The parameter to control vertical or horizontal is vert, which accepts True or False.
Step 2: Match correct syntax
Using plt.boxplot(data, vert=True) creates a vertical box plot correctly.
Final Answer:
plt.boxplot(data, vert=True) -> Option C
Quick Check:
Use vert=True for vertical boxplot [OK]
Hint: Use vert=True for vertical boxplot in plt.boxplot [OK]
Common Mistakes:
Using wrong parameter name like 'vertical'
Passing string instead of boolean for vert
Confusing orientation parameter which plt.boxplot doesn't use
3. What will be the output of the following code?
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(0)
data = np.random.normal(0, 1, 100)
plt.boxplot(data, notch=True)
plt.show()
medium
A. An error because notch=True is invalid
B. A scatter plot of the 100 data points
C. A histogram of the data distribution
D. A box plot with a notch showing median confidence interval
Solution
Step 1: Understand the code
The code generates 100 random normal values and plots a box plot with notch=True.
Step 2: Interpret notch=True effect
The notch creates a narrow region around the median to indicate confidence interval visually.
Final Answer:
A box plot with a notch showing median confidence interval -> Option D
Quick Check:
notch=True adds median confidence notch [OK]
Hint: notch=True adds median confidence notch in boxplot [OK]
Common Mistakes:
Thinking notch=True creates scatter or histogram
Assuming notch=True causes error
Confusing boxplot with other plot types
4. Identify the error in this code snippet that tries to plot a box plot:
import matplotlib.pyplot as plt
data = [1, 2, 3, 4, 5]
plt.boxplot(data, notch='yes')
plt.show()
medium
A. The 'notch' parameter should be a boolean, not a string
B. The data list must be a numpy array
C. plt.boxplot requires data to be a dictionary
D. plt.show() is missing
Solution
Step 1: Check the 'notch' parameter type
The 'notch' parameter expects a boolean (True or False), not a string like 'yes'.
Step 2: Confirm data type and plt.show()
Data as list is valid, and plt.show() is present, so no error there.
Final Answer:
The 'notch' parameter should be a boolean, not a string -> Option A
Quick Check:
notch must be True or False, not 'yes' [OK]
Hint: Use True/False for notch, not strings [OK]
Common Mistakes:
Passing string instead of boolean for notch
Thinking data must be numpy array
Forgetting plt.show() (not error here though)
5. You have two datasets: data1 and data2. You want to compare their distributions side by side using box plots with different colors and horizontal orientation. Which code snippet correctly achieves this?
hard
A. plt.boxplot([data1, data2], vert=False, patch_artist=True, boxprops=[dict(facecolor='lightblue'), dict(facecolor='orange')])
B. plt.boxplot(data1, data2, vert=True, color=['red', 'green'])
C. plt.boxplot([data1, data2], orientation='horizontal', colors=['blue', 'orange'])
D. plt.boxplot([data1, data2], vert=True, patch_artist=True, boxprops=dict(facecolor='red'))
Solution
Step 1: Check data input format
To plot multiple datasets side by side, pass a list of datasets: [data1, data2].
Step 2: Verify horizontal orientation and color options
Use vert=False for horizontal boxplots, patch_artist=True to fill boxes with color, and boxprops to set facecolor.
Step 3: Evaluate options
plt.boxplot([data1, data2], vert=False, patch_artist=True, boxprops=[dict(facecolor='lightblue'), dict(facecolor='orange')]) correctly uses these parameters. Options A, B, and D use invalid parameters or syntax. plt.boxplot([data1, data2], vert=True, patch_artist=True, boxprops=dict(facecolor='red')) is vertical, not horizontal.
Final Answer:
plt.boxplot([data1, data2], vert=False, patch_artist=True, boxprops=[dict(facecolor='lightblue'), dict(facecolor='orange')]) -> Option A
Quick Check:
Multiple data + vert=False + patch_artist for color [OK]
Hint: Use vert=False and patch_artist=True for colored horizontal boxplots [OK]
Common Mistakes:
Passing datasets separately instead of as list
Using wrong parameter names like 'orientation'
Forgetting patch_artist=True to fill colors
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.