Challenge - 5 Problems
Marker Size Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of varying marker sizes in scatter plot
What will be the output of the following code snippet that uses matplotlib to plot points with different marker sizes?
Matplotlib
import matplotlib.pyplot as plt sizes = [20, 50, 80, 200] x = [1, 2, 3, 4] y = [10, 20, 25, 30] plt.scatter(x, y, s=sizes) plt.show()
Attempts:
2 left
💡 Hint
The 's' parameter in plt.scatter controls the marker size for each point individually if given a list.
✗ Incorrect
The 's' argument accepts a list of sizes, so each point gets its own size. The plot will show points with sizes 20, 50, 80, and 200 respectively.
❓ data_output
intermediate1:30remaining
Number of points with marker size greater than 50
Given the following code, how many points have marker sizes greater than 50?
Matplotlib
import matplotlib.pyplot as plt sizes = [10, 60, 45, 90, 30] x = [1, 2, 3, 4, 5] y = [5, 15, 10, 20, 25] plt.scatter(x, y, s=sizes) plt.show()
Attempts:
2 left
💡 Hint
Check the sizes list and count how many values are greater than 50.
✗ Incorrect
Only the sizes 60 and 90 are greater than 50, so 2 points have marker sizes greater than 50.
🔧 Debug
advanced2:00remaining
Identify the error in marker size assignment
What error will this code raise when trying to plot marker sizes?
Matplotlib
import matplotlib.pyplot as plt sizes = '20, 40, 60' x = [1, 2, 3] y = [5, 10, 15] plt.scatter(x, y, s=sizes) plt.show()
Attempts:
2 left
💡 Hint
Check the type of 'sizes' and what plt.scatter expects for 's'.
✗ Incorrect
The 'sizes' variable is a string, not a list or array of numbers. plt.scatter expects a scalar or sequence of numbers for 's'. Passing a string causes a ValueError.
❓ visualization
advanced2:00remaining
Effect of marker size scaling on scatter plot
Which option correctly describes the visual difference when doubling the marker sizes in this scatter plot?
Matplotlib
import matplotlib.pyplot as plt sizes = [30, 60, 90] x = [1, 2, 3] y = [10, 20, 30] plt.scatter(x, y, s=[size * 2 for size in sizes]) plt.show()
Attempts:
2 left
💡 Hint
Remember that 's' controls marker area, not diameter.
✗ Incorrect
The 's' parameter controls the area of markers. Doubling 's' doubles the area, so markers appear larger but diameter increases by sqrt(2), not 2.
🚀 Application
expert2:30remaining
Create a scatter plot with marker sizes proportional to y-values
Which code snippet correctly creates a scatter plot where marker sizes are proportional to the y-values multiplied by 10?
Attempts:
2 left
💡 Hint
You need to multiply each y-value by 10 to get marker sizes.
✗ Incorrect
Option A correctly multiplies each y-value by 10 using a list comprehension. Option A causes a TypeError because y is a list and cannot be multiplied directly. Option A creates a list with one element, not sizes for each point. Option A multiplies x-values, not y-values.