0
0
Matplotlibdata~20 mins

Basic scatter plot with plt.scatter in Matplotlib - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Scatter Plot Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a simple scatter plot code
What will be the output of this code snippet that uses plt.scatter to plot points?
Matplotlib
import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [4, 5, 6]
plt.scatter(x, y)
plt.show()
AAn error because plt.scatter requires color argument.
BA line plot connecting points (1,4), (2,5), and (3,6).
CA scatter plot with three points at coordinates (1,4), (2,5), and (3,6) displayed.
DA bar chart with bars at x=1,2,3 and heights 4,5,6.
Attempts:
2 left
💡 Hint
Remember, plt.scatter plots points, not lines or bars.
data_output
intermediate
1:30remaining
Number of points plotted by plt.scatter
How many points will be plotted by this code?
Matplotlib
import matplotlib.pyplot as plt
x = [10, 20, 30, 40]
y = [1, 2, 3, 4]
plt.scatter(x, y)
plt.show()
A4
B3
C5
D0
Attempts:
2 left
💡 Hint
Count the number of x or y values given.
🔧 Debug
advanced
2:00remaining
Identify the error in scatter plot code
What error will this code produce?
Matplotlib
import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [4, 5]
plt.scatter(x, y)
plt.show()
AValueError: x and y must be the same size
BTypeError: plt.scatter() missing required positional argument
CNo error, plot shows 2 points
DIndexError: list index out of range
Attempts:
2 left
💡 Hint
Check if x and y lists have the same length.
visualization
advanced
2:00remaining
Effect of marker size in plt.scatter
What will be the visual difference when running this code compared to default marker size?
Matplotlib
import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [4, 5, 6]
plt.scatter(x, y, s=200)
plt.show()
APoints will appear smaller than default size.
BCode will raise an error due to invalid size argument.
CPoints will be connected by lines.
DPoints will appear larger than default size.
Attempts:
2 left
💡 Hint
The 's' parameter controls marker size in plt.scatter.
🚀 Application
expert
3:00remaining
Plotting two groups with different colors using plt.scatter
Which code correctly plots two groups of points in different colors on the same scatter plot?
A
import matplotlib.pyplot as plt
x1, y1 = [1,2], [3,4]
x2, y2 = [5,6], [7,8]
plt.scatter(x1, y1)
plt.scatter(x2, y2)
plt.show()
B
import matplotlib.pyplot as plt
x1, y1 = [1,2], [3,4]
x2, y2 = [5,6], [7,8]
plt.scatter(x1, y1, color='red')
plt.scatter(x2, y2, color='blue')
plt.show()
C
import matplotlib.pyplot as plt
x = [1,2,5,6]
y = [3,4,7,8]
plt.scatter(x, y, color=['red', 'red', 'blue', 'blue'])
plt.show()
D
import matplotlib.pyplot as plt
x = [1,2,5,6]
y = [3,4,7,8]
plt.scatter(x, y, c='red blue')
plt.show()
Attempts:
2 left
💡 Hint
Use separate plt.scatter calls with color argument for each group.