Look at the scatter plot created by the code below. What pattern does it show about the relationship between x and y?
import matplotlib.pyplot as plt import numpy as np np.random.seed(0) x = np.arange(10) y = 2 * x + np.random.normal(0, 1, 10) plt.scatter(x, y) plt.title('Scatter plot of x vs y') plt.xlabel('x') plt.ylabel('y') plt.show()
Look at how the points move as x gets bigger. Do they go up, down, or stay random?
The scatter plot shows points roughly forming a line that goes up from left to right, indicating a positive linear relationship between x and y.
Given the code below that plots a bar chart of fruit counts, how many total fruits are counted?
import matplotlib.pyplot as plt fruits = ['apple', 'banana', 'orange', 'apple', 'banana', 'apple'] from collections import Counter counts = Counter(fruits) plt.bar(counts.keys(), counts.values()) plt.title('Fruit counts') plt.show() print(sum(counts.values()))
Count how many fruits are in the list, not just unique types.
The list has 6 fruits total, so the sum of counts is 6.
What is the output of the following code that creates a histogram and prints the bin counts?
import matplotlib.pyplot as plt import numpy as np data = np.array([1, 2, 2, 3, 5, 5, 5, 5, 6]) counts, bins, patches = plt.hist(data, bins=3) plt.close() print(counts)
Check how the data values fall into 3 equal bins between min and max.
The bins split the data into ranges: [1-2.666), [2.666-4.333), [4.333-6]. Counts are 3, 1, and 5 respectively.
Which statement best explains why box plots help reveal data patterns?
Think about what parts of the data a box plot highlights.
Box plots show median, quartiles, and highlight outliers, summarizing the data spread and spotting unusual values.
What error does the following code produce when run?
import matplotlib.pyplot as plt x = [1, 2, 3] y = [4, 5] plt.plot(x, y) plt.show()
Check if x and y lists have the same length.
Matplotlib requires x and y to have the same length to plot points. Here, x has 3 elements but y has 2, causing a ValueError.