Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to plot a normalized histogram using matplotlib.
Matplotlib
import matplotlib.pyplot as plt data = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4] plt.hist(data, density=[1]) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using density=False will plot counts instead of probabilities.
Passing None or 0 does not normalize the histogram.
✗ Incorrect
Setting density=True normalizes the histogram so the area sums to 1.
2fill in blank
mediumComplete the code to plot a normalized histogram with 5 bins.
Matplotlib
import matplotlib.pyplot as plt values = [5, 7, 7, 8, 9, 10, 10, 10, 11] plt.hist(values, bins=[1], density=True) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using too few bins can hide data details.
Using too many bins can make the histogram noisy.
✗ Incorrect
Setting bins=5 divides the data into 5 equal-width bins.
3fill in blank
hardFix the error in the code to correctly plot a normalized histogram.
Matplotlib
import matplotlib.pyplot as plt scores = [60, 70, 70, 80, 90, 90, 90, 100] plt.hist(scores, bins=4, [1]=True) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using deprecated or incorrect parameter names like 'normed'.
Using 'normalize' or 'probability' which are not valid parameters.
✗ Incorrect
The correct parameter to normalize histograms in matplotlib is density.
4fill in blank
hardFill both blanks to create a normalized histogram with 6 bins and blue color.
Matplotlib
import matplotlib.pyplot as plt ages = [22, 25, 25, 30, 35, 35, 40, 45, 50] plt.hist(ages, bins=[1], density=[2], color='blue') plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using density=False will not normalize the histogram.
Setting bins to 5 instead of 6 changes the bin count.
✗ Incorrect
Use bins=6 to set six bins and density=True to normalize the histogram.
5fill in blank
hardFill all three blanks to create a normalized histogram with red color, 4 bins, and alpha transparency 0.7.
Matplotlib
import matplotlib.pyplot as plt weights = [55, 60, 65, 70, 75, 80, 85, 90] plt.hist(weights, bins=[1], density=[2], color=[3], alpha=0.7) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up color strings or using wrong bin counts.
Setting density to False will not normalize the histogram.
✗ Incorrect
Set bins=4 for four bins, density=True to normalize, and color='red' for red bars.