Challenge - 5 Problems
Statistical Plot Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Effect of adding a KDE curve to a histogram
What will be the output of this code snippet that plots a histogram with a KDE curve using matplotlib and seaborn?
Matplotlib
import matplotlib.pyplot as plt import seaborn as sns import numpy as np data = np.random.normal(loc=0, scale=1, size=1000) sns.histplot(data, kde=True, color='skyblue') plt.title('Histogram with KDE curve') plt.show()
Attempts:
2 left
💡 Hint
The 'kde=True' parameter adds a smooth curve over the histogram.
✗ Incorrect
The sns.histplot function with kde=True draws both the histogram bars and a smooth kernel density estimate curve on top. The bars are colored skyblue, and the KDE curve is black by default.
❓ data_output
intermediate1:30remaining
Number of bins in a histogram with automatic binning
Given this code, how many bins will the histogram have approximately?
Matplotlib
import matplotlib.pyplot as plt import numpy as np data = np.random.uniform(0, 10, 500) plt.hist(data, bins='auto') plt.show()
Attempts:
2 left
💡 Hint
The 'auto' binning method tries to find a good number of bins based on data size and distribution.
✗ Incorrect
The 'auto' option in matplotlib's hist function usually selects a bin count around the square root of the number of data points or uses other heuristics. For 500 points, this is roughly 20 bins.
❓ visualization
advanced2:30remaining
Customizing boxplot whiskers to show 5th and 95th percentiles
Which code snippet correctly creates a boxplot where whiskers extend to the 5th and 95th percentiles instead of the default 1.5 IQR?
Attempts:
2 left
💡 Hint
The 'whis' parameter accepts percentiles (0-100) when given as a tuple.
✗ Incorrect
To set whiskers at the 5th and 95th percentiles, use whis=(5, 95). Passing values between 0 and 100 in a tuple tells matplotlib to use those percentiles. Passing small fractions like 0.05 will not work as intended.
🔧 Debug
advanced2:00remaining
Identify the error in this violin plot code
What error will this code produce when run?
Matplotlib
import matplotlib.pyplot as plt import numpy as np data = [np.random.normal(size=100), np.random.normal(loc=2, size=100)] plt.violinplot(data, positions=[1, 2, 3]) plt.show()
Attempts:
2 left
💡 Hint
Check if the number of positions matches the number of datasets.
✗ Incorrect
The violinplot function expects the positions list length to match the number of datasets. Here, data has length 2 but positions has length 3, causing a ValueError.
🚀 Application
expert3:00remaining
Enhancing a scatter plot with marginal histograms
Which code snippet correctly creates a scatter plot with histograms on the top and right margins using matplotlib's gridspec?
Attempts:
2 left
💡 Hint
The scatter plot should occupy the larger bottom-left area, histograms on top and right margins.
✗ Incorrect
To create marginal histograms, the figure is divided into a 2x2 grid with width_ratios and height_ratios set so the scatter plot is larger (bottom-left). Histograms go on top-left (top margin) and bottom-right (right margin).