Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the library needed to create histograms.
Matplotlib
import [1] as plt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing numpy instead of matplotlib.pyplot
Importing pandas which is for data frames
Importing seaborn which is a different plotting library
✗ Incorrect
We use matplotlib.pyplot to create histograms in Python.
2fill in blank
mediumComplete the code to create a histogram of the data list.
Matplotlib
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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using plot which makes a line graph
Using scatter which makes a scatter plot
Using bar which makes bar charts but not histograms
✗ Incorrect
The hist function creates a histogram to show data distribution.
3fill in blank
hardFix the error in the code to correctly label the x-axis.
Matplotlib
plt.hist(data)
plt.xlabel([1])
plt.show() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names without quotes
Using incorrect function names
Forgetting quotes around label text
✗ Incorrect
The label text must be a string, so it needs quotes.
4fill in blank
hardFill both blanks to create a histogram with 5 bins and a title.
Matplotlib
plt.hist(data, bins=[1]) plt.title([2]) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using too many bins like 10
Not putting the title in quotes
Confusing bins with title
✗ Incorrect
Setting bins to 5 groups data into 5 parts. The title must be a string.
5fill in blank
hardFill all three blanks to create a histogram with green color, 8 bins, and x-axis label 'Scores'.
Matplotlib
plt.hist(data, bins=[1], color=[2]) plt.xlabel([3]) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using color without quotes
Using numbers instead of strings for labels
Mixing up color names
✗ Incorrect
Bins is a number (8), color is a string ('green'), and xlabel is a string ('Scores').