0
0
Matplotlibdata~10 mins

Normalized histograms in Matplotlib - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
ANone
BFalse
CTrue
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using density=False will plot counts instead of probabilities.
Passing None or 0 does not normalize the histogram.
2fill in blank
medium

Complete 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'
A3
B10
C7
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using too few bins can hide data details.
Using too many bins can make the histogram noisy.
3fill in blank
hard

Fix 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'
Anormalize
Bdensity
Cnormed
Dprobability
Attempts:
3 left
💡 Hint
Common Mistakes
Using deprecated or incorrect parameter names like 'normed'.
Using 'normalize' or 'probability' which are not valid parameters.
4fill in blank
hard

Fill 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'
A6
BTrue
CFalse
D5
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.
5fill in blank
hard

Fill 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'
ATrue
B4
C'red'
D'blue'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up color strings or using wrong bin counts.
Setting density to False will not normalize the histogram.