0
0
Matplotlibdata~20 mins

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

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Matplotlib Plot Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What does this matplotlib code plot?
Consider the following Python code using matplotlib. What kind of plot will it produce?
Matplotlib
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [10, 20, 25, 30]
plt.plot(x, y)
plt.show()
AA line graph connecting points (1,10), (2,20), (3,25), (4,30)
BA scatter plot with points at (1,10), (2,20), (3,25), (4,30)
CA bar chart with bars at x=1,2,3,4 with heights 10,20,25,30
DAn empty plot with no data shown
Attempts:
2 left
💡 Hint
plt.plot by default draws lines connecting points.
data_output
intermediate
1:30remaining
What is the y-value of the third point plotted?
Given this code snippet, what is the y-value of the third point plotted?
Matplotlib
import matplotlib.pyplot as plt
x = [0, 1, 2, 3]
y = [5, 15, 25, 35]
plt.plot(x, y)
plt.show()
A25
B15
C35
D5
Attempts:
2 left
💡 Hint
Indexing starts at 0, so the third point is at index 2.
visualization
advanced
2:30remaining
Which option produces a red dashed line plot?
Which code snippet will produce a red dashed line connecting points (1,2), (2,4), (3,6)?
Aplt.plot([1,2,3], [2,4,6], 'g-')
Bplt.plot([1,2,3], [2,4,6], color='blue', linestyle='--')
Cplt.plot([1,2,3], [2,4,6], 'r--')
Dplt.plot([1,2,3], [2,4,6], linestyle=':')
Attempts:
2 left
💡 Hint
The format string 'r--' means red dashed line.
🔧 Debug
advanced
2:00remaining
What error does this code raise?
What error will this code raise when executed?
Matplotlib
import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [4, 5]
plt.plot(x, y)
plt.show()
ATypeError: unsupported operand type(s)
BValueError: x and y must have same first dimension
CIndexError: list index out of range
DNo error, plot will display correctly
Attempts:
2 left
💡 Hint
x and y lists must be the same length for plt.plot.
🚀 Application
expert
2:30remaining
How many lines will this code plot?
Given this code, how many separate lines will appear in the plot?
Matplotlib
import matplotlib.pyplot as plt
x = [1, 2, 3]
y1 = [2, 4, 6]
y2 = [1, 3, 5]
plt.plot(x, y1, x, y2)
plt.show()
A3
B1
C0
D2
Attempts:
2 left
💡 Hint
plt.plot can take multiple x,y pairs to plot multiple lines.