0
0
Matplotlibdata~10 mins

Basic histogram with plt.hist 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 create a histogram of the data list using matplotlib.

Matplotlib
import matplotlib.pyplot as plt

data = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]
plt.[1](data)
plt.show()
Drag options to blanks, or click blank then click option'
Abar
Bscatter
Cplot
Dhist
Attempts:
3 left
💡 Hint
Common Mistakes
Using plt.plot() instead of plt.hist()
Using plt.scatter() which is for scatter plots
Using plt.bar() which is for bar charts
2fill in blank
medium

Complete the code to set the number of bins to 4 in the histogram.

Matplotlib
import matplotlib.pyplot as plt

data = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]
plt.hist(data, bins=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A4
B3
C5
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using too few or too many bins that don't match the question
Forgetting to set the bins parameter
3fill in blank
hard

Fix the error in the code to correctly display the histogram with labels.

Matplotlib
import matplotlib.pyplot as plt

data = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]
plt.hist(data)
plt.xlabel([1])
plt.ylabel('Frequency')
plt.show()
Drag options to blanks, or click blank then click option'
AFrequency
B'Value'
DValue
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the label text
Using a variable name instead of a string
4fill in blank
hard

Fill both blanks to create a histogram with 5 bins and a title.

Matplotlib
import matplotlib.pyplot as plt

data = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]
plt.hist(data, bins=[1])
plt.title([2])
plt.show()
Drag options to blanks, or click blank then click option'
A5
B'Histogram of Data'
C'Data Histogram'
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string for bins or a number without quotes for title
Forgetting to put quotes around the title
5fill in blank
hard

Fill all three blanks to create a histogram with 6 bins, x-label, and y-label.

Matplotlib
import matplotlib.pyplot as plt

data = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]
plt.hist(data, bins=[1])
plt.xlabel([2])
plt.ylabel([3])
plt.show()
Drag options to blanks, or click blank then click option'
A6
B'Value'
C'Frequency'
D'Count'
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the label strings
Using wrong numbers for bins