B. A histogram showing frequency distribution of numbers
C. A scatter plot of numbers against their indices
D. A line plot connecting the numbers in order
Solution
Step 1: Understand plt.hist() function
plt.hist() creates a histogram showing frequency counts of data bins.
Step 2: Analyze the data input
The list has repeated numbers; histogram will show how often each appears.
Final Answer:
A histogram showing frequency distribution of numbers -> Option B
Quick Check:
plt.hist() = histogram frequency plot [OK]
Hint: plt.hist() creates frequency distribution plots [OK]
Common Mistakes:
Confusing histogram with bar chart
Expecting scatter or line plot from plt.hist()
Not understanding frequency bins
4. The code below is intended to plot a scatter plot but does not show any points. What is the error?
import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [4, 5, 6]
plt.scatter(x, y)
plt.show()
medium
A. Nothing is wrong; the plot will show points.
B. plt.scatter() is misspelled; should be plt.scatterplot()
C. plt.show() is missing, so plot won't display.
D. x and y lists must be numpy arrays, not lists.
Solution
Step 1: Check the code syntax and functions
plt.scatter() is the correct function to plot scatter points; x and y are valid lists.
Step 2: Confirm plot display commands
plt.show() is present, so the plot will display points as expected.
Final Answer:
Nothing is wrong; the plot will show points. -> Option A
Quick Check:
Correct function and plt.show() present = plot visible [OK]
Hint: plt.scatter() with plt.show() displays points [OK]
Common Mistakes:
Thinking plt.scatterplot() is correct function
Believing plt.show() is missing
Assuming lists can't be used for plotting
5. You have a dataset with many values and want to quickly see if there are any unusual points (outliers). Which matplotlib plot is best to reveal this pattern clearly?
hard
A. Scatter plot
B. Line plot
C. Pie chart
D. Box plot
Solution
Step 1: Identify plot types and their uses
Box plots summarize data distribution and highlight outliers clearly.
Step 2: Compare with other plot types
Line plots show trends, pie charts show parts of a whole, scatter plots show relationships but less clear for outliers.