Challenge - 5 Problems
Error Bar Plot Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of error bar plot with asymmetric errors
What will be the output of this code snippet that creates an error bar plot with asymmetric errors?
Matplotlib
import matplotlib.pyplot as plt import numpy as np x = np.array([1, 2, 3, 4]) y = np.array([2, 3, 5, 7]) yerr = [0.5, 0.2, 0.3, 0.4] yerr_upper = [0.6, 0.3, 0.4, 0.5] plt.errorbar(x, y, yerr=[yerr, yerr_upper], fmt='o') plt.show()
Attempts:
2 left
💡 Hint
Check how yerr is passed as a list of two arrays to specify asymmetric errors.
✗ Incorrect
When yerr is a list of two arrays, the first array specifies the lower errors and the second array specifies the upper errors, creating asymmetric error bars.
❓ data_output
intermediate1:30remaining
Number of error bars plotted
Given this code, how many error bars will be drawn on the plot?
Matplotlib
import matplotlib.pyplot as plt import numpy as np x = np.arange(5) y = np.array([1, 4, 9, 16, 25]) errors = np.array([0.1, 0.2, 0.3, 0.4, 0.5]) plt.errorbar(x, y, yerr=errors, fmt='s') plt.show()
Attempts:
2 left
💡 Hint
Each point gets one error bar with symmetric upper and lower parts.
✗ Incorrect
Each point has one error bar with symmetric upper and lower error lengths equal to the yerr value. So 5 points mean 5 error bars.
🔧 Debug
advanced2:00remaining
Identify the error in error bar plot code
What error will this code raise when run?
Matplotlib
import matplotlib.pyplot as plt import numpy as np x = np.array([1, 2, 3]) y = np.array([2, 4, 6]) yerr = np.array([0.1, 0.2]) plt.errorbar(x, y, yerr=yerr, fmt='o') plt.show()
Attempts:
2 left
💡 Hint
Check if yerr length matches y length.
✗ Incorrect
The yerr array length (2) does not match y length (3), so matplotlib raises a ValueError about size mismatch.
❓ visualization
advanced2:00remaining
Effect of capsize parameter in error bar plots
Which option best describes the visual effect of setting capsize=10 in this error bar plot code?
Matplotlib
import matplotlib.pyplot as plt import numpy as np x = np.arange(4) y = np.array([3, 5, 7, 9]) errors = np.array([0.5, 0.4, 0.3, 0.2]) plt.errorbar(x, y, yerr=errors, fmt='o', capsize=10) plt.show()
Attempts:
2 left
💡 Hint
Capsize controls the width of the horizontal line at the error bar ends.
✗ Incorrect
The capsize parameter sets the length of the horizontal caps at the ends of the vertical error bars in points (pixels).
🚀 Application
expert3:00remaining
Calculate mean and plot with error bars showing standard error
You have three groups of data points:
Group A: [5, 7, 8, 6]
Group B: [6, 9, 7, 10]
Group C: [8, 12, 11, 9]
Which code correctly calculates the mean and standard error of the mean (SEM) for each group and plots them with error bars?
Attempts:
2 left
💡 Hint
Use sample standard deviation (ddof=1) to calculate SEM correctly.
✗ Incorrect
Standard error of the mean is calculated as sample standard deviation (with ddof=1) divided by square root of sample size. Option A uses this formula correctly.