0
0
Matplotlibdata~20 mins

Marker size variation in Matplotlib - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Marker Size Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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()
AA scatter plot with 4 points, each point having marker sizes 20, 50, 80, and 200 respectively.
BA scatter plot with 4 points, but all markers are invisible because size is zero.
CA scatter plot with 4 points, all having the same marker size equal to the sum of sizes list.
DA scatter plot with 4 points, but marker sizes are ignored and default size is used.
Attempts:
2 left
💡 Hint
The 's' parameter in plt.scatter controls the marker size for each point individually if given a list.
data_output
intermediate
1: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()
A3
B2
C1
D4
Attempts:
2 left
💡 Hint
Check the sizes list and count how many values are greater than 50.
🔧 Debug
advanced
2: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()
ATypeError: float() argument must be a string or a number, not 'tuple'
BNo error, plot displays with marker sizes 20, 40, 60
CTypeError: 'str' object is not iterable
DValueError: s must be a scalar or sequence of scalars
Attempts:
2 left
💡 Hint
Check the type of 'sizes' and what plt.scatter expects for 's'.
visualization
advanced
2: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()
AMarkers appear the same size as original because scaling is ignored.
BMarkers appear twice as large in diameter compared to original sizes.
CMarkers appear twice as large in area compared to original sizes.
DMarkers appear half the size of original because sizes are divided.
Attempts:
2 left
💡 Hint
Remember that 's' controls marker area, not diameter.
🚀 Application
expert
2: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?
Aplt.scatter(x, y, s=[val * 10 for val in y])
Bplt.scatter(x, y, s=y * 10)
Cplt.scatter(x, y, s=[y * 10])
Dplt.scatter(x, y, s=list(map(lambda x: x*10, x)))
Attempts:
2 left
💡 Hint
You need to multiply each y-value by 10 to get marker sizes.