Challenge - 5 Problems
Box and Violin Plot Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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))
Attempts:
2 left
💡 Hint
Check the type of the variable 'data' before plotting.
✗ Incorrect
The variable 'data' is created using numpy's random.normal function, which returns a numpy ndarray. The print statement outputs its type.
❓ data_output
intermediate2: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))
Attempts:
2 left
💡 Hint
Count the number of elements in each normal distribution and sum them.
✗ Incorrect
The data is created by concatenating two arrays of 50 elements each, so total 100 points.
❓ visualization
advanced2:00remaining
Identify the Plot Type from Description
Which plot type shows the full distribution shape of the data along with median and quartiles?
Attempts:
2 left
💡 Hint
One plot uses kernel density estimation to show distribution shape.
✗ Incorrect
Violin plots show the full distribution shape using kernel density estimation, while box plots show summary statistics only.
🧠 Conceptual
advanced2:00remaining
Difference in Outlier Representation
Which statement correctly describes how outliers are represented in box plots and violin plots?
Attempts:
2 left
💡 Hint
Think about how each plot visualizes data extremes.
✗ Incorrect
Box plots mark outliers as points beyond whiskers; violin plots show density but do not mark outliers explicitly.
🔧 Debug
expert2: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()
Attempts:
2 left
💡 Hint
Check if matplotlib supports plotting boxplot and violinplot on same axes.
✗ Incorrect
Matplotlib allows plotting boxplot and violinplot on the same axes without error.