0
0
Matplotlibdata~20 mins

Why scatter plots show relationships in Matplotlib - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Scatter Plot Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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()
AA scatter plot showing points in a straight line going up, indicating a positive linear relationship.
BA scatter plot showing points randomly scattered with no clear pattern.
CA scatter plot showing points in a straight line going down, indicating a negative linear relationship.
DA scatter plot showing points clustered at the origin with no spread.
Attempts:
2 left
💡 Hint
Look at how y changes as x increases.
data_output
intermediate
1: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)
A3
B4
C5
D6
Attempts:
2 left
💡 Hint
Count the number of elements in the x list.
visualization
advanced
2: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()
APlot A
BPlot C
CPlot D
DPlot B
Attempts:
2 left
💡 Hint
Look for points that go down as x increases.
🧠 Conceptual
advanced
1: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?
ABecause scatter plots show individual data points, making it easy to see patterns like trends or clusters.
BBecause scatter plots only show averages, hiding individual differences.
CBecause scatter plots connect points with lines to show exact changes over time.
DBecause scatter plots use bars to compare categories clearly.
Attempts:
2 left
💡 Hint
Think about what you see when you look at a scatter plot.
🔧 Debug
expert
2: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()
ATypeError: 'list' object is not callable
BValueError: x and y must be the same size
CSyntaxError: invalid syntax
DNo error, plot will display correctly
Attempts:
2 left
💡 Hint
Check if x and y have the same number of elements.