0
0
Matplotlibdata~20 mins

Box plot vs violin plot comparison in Matplotlib - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Box and Violin Plot Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of Box Plot Code
What will be the output of the following Python code that creates a box plot using matplotlib?
Matplotlib
import matplotlib.pyplot as plt
import numpy as np

data = np.random.normal(0, 1, 100)
plt.boxplot(data)
plt.savefig('boxplot.png')
plt.close()
print(type(data))
ASyntaxError
B<class 'list'>
C<class 'numpy.ndarray'>
D<class 'matplotlib.figure.Figure'>
Attempts:
2 left
💡 Hint
Check the type of the variable 'data' before plotting.
data_output
intermediate
2:00remaining
Data Points in Violin Plot
Given the following code that creates a violin plot, how many data points are used to create the plot?
Matplotlib
import matplotlib.pyplot as plt
import numpy as np

data = np.concatenate([np.random.normal(0, 1, 50), np.random.normal(5, 1, 50)])
plt.violinplot(data)
plt.close()
print(len(data))
A100
B50
C150
D200
Attempts:
2 left
💡 Hint
Count the number of elements in each normal distribution and sum them.
visualization
advanced
2:00remaining
Identify the Plot Type from Description
Which plot type shows the full distribution shape of the data along with median and quartiles?
ABox plot
BViolin plot
CScatter plot
DHistogram
Attempts:
2 left
💡 Hint
One plot uses kernel density estimation to show distribution shape.
🧠 Conceptual
advanced
2:00remaining
Difference in Outlier Representation
Which statement correctly describes how outliers are represented in box plots and violin plots?
ANeither box plots nor violin plots show outliers explicitly.
BViolin plots show outliers as individual points; box plots do not explicitly mark outliers.
CBoth box plots and violin plots show outliers as individual points.
DBox plots show outliers as individual points; violin plots do not explicitly mark outliers.
Attempts:
2 left
💡 Hint
Think about how each plot visualizes data extremes.
🔧 Debug
expert
2:00remaining
Error in Combined Box and Violin Plot Code
What error will this code produce when trying to plot both box and violin plots on the same axes?
Matplotlib
import matplotlib.pyplot as plt
import numpy as np

data = np.random.normal(size=100)
fig, ax = plt.subplots()
ax.boxplot(data)
ax.violinplot(data)
plt.show()
ANo error; both plots display correctly.
BRuntimeWarning: Attempting to plot incompatible plot types
CValueError: data must be 2D array for violinplot
DTypeError: violinplot() got an unexpected keyword argument
Attempts:
2 left
💡 Hint
Check if matplotlib supports plotting boxplot and violinplot on same axes.