Challenge - 5 Problems
Matplotlib Plot Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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()
Attempts:
2 left
💡 Hint
plt.plot by default draws lines connecting points.
✗ Incorrect
The plt.plot function draws a line graph connecting the points given by x and y lists.
❓ data_output
intermediate1: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()
Attempts:
2 left
💡 Hint
Indexing starts at 0, so the third point is at index 2.
✗ Incorrect
The third point corresponds to index 2 in the y list, which is 25.
❓ visualization
advanced2: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)?
Attempts:
2 left
💡 Hint
The format string 'r--' means red dashed line.
✗ Incorrect
The 'r--' format string sets the line color to red and line style to dashed.
🔧 Debug
advanced2: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()
Attempts:
2 left
💡 Hint
x and y lists must be the same length for plt.plot.
✗ Incorrect
The x list has length 3 but y has length 2, causing a ValueError.
🚀 Application
expert2: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()
Attempts:
2 left
💡 Hint
plt.plot can take multiple x,y pairs to plot multiple lines.
✗ Incorrect
The code plots two lines: one for (x,y1) and one for (x,y2).