Challenge - 5 Problems
Scatter Plot Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this scatter plot code?
Look at the code below that creates a scatter plot. What will the plot show about the relationship between x and y?
Matplotlib
import matplotlib.pyplot as plt x = [1, 2, 3, 4, 5] y = [2, 4, 6, 8, 10] plt.scatter(x, y) plt.show()
Attempts:
2 left
💡 Hint
Look at how y changes as x increases.
✗ Incorrect
The y values are exactly twice the x values, so the points form a straight line going up. This shows a positive linear relationship.
❓ data_output
intermediate1:30remaining
How many points are plotted in this scatter plot?
Given the data below, how many points will appear in the scatter plot?
Matplotlib
import matplotlib.pyplot as plt x = [5, 3, 9, 1, 7] y = [10, 6, 18, 2, 14] plt.scatter(x, y) plt.show() num_points = len(x)
Attempts:
2 left
💡 Hint
Count the number of elements in the x list.
✗ Incorrect
There are 5 elements in the x list, so 5 points will be plotted.
❓ visualization
advanced2:30remaining
Which scatter plot shows a negative relationship?
Below are four scatter plots created from different data sets. Which plot shows a negative relationship between x and y?
Matplotlib
import matplotlib.pyplot as plt import numpy as np fig, axs = plt.subplots(2, 2, figsize=(8, 6)) # Plot A: Positive linear x = np.arange(10) y = 2 * x + 1 axs[0, 0].scatter(x, y) axs[0, 0].set_title('A') # Plot B: Negative linear x = np.arange(10) y = 10 - x axs[0, 1].scatter(x, y) axs[0, 1].set_title('B') # Plot C: No relationship x = np.random.rand(10) y = np.random.rand(10) axs[1, 0].scatter(x, y) axs[1, 0].set_title('C') # Plot D: Clustered points x = np.ones(10) y = np.linspace(0, 5, 10) axs[1, 1].scatter(x, y) axs[1, 1].set_title('D') plt.tight_layout() plt.show()
Attempts:
2 left
💡 Hint
Look for points that go down as x increases.
✗ Incorrect
Plot B shows y decreasing as x increases, which is a negative linear relationship.
🧠 Conceptual
advanced1:30remaining
Why do scatter plots help show relationships between variables?
Which explanation best describes why scatter plots are useful to see relationships between two variables?
Attempts:
2 left
💡 Hint
Think about what you see when you look at a scatter plot.
✗ Incorrect
Scatter plots display each data point, so you can see how variables relate by spotting patterns or groupings.
🔧 Debug
expert2:00remaining
What error does this scatter plot code produce?
Look at the code below. What error will occur when running it?
Matplotlib
import matplotlib.pyplot as plt x = [1, 2, 3] y = [4, 5] plt.scatter(x, y) plt.show()
Attempts:
2 left
💡 Hint
Check if x and y have the same number of elements.
✗ Incorrect
The x list has 3 elements but y has 2, so matplotlib raises a ValueError about size mismatch.