Challenge - 5 Problems
Line Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat is the color of the line in this plot?
Look at the code below that plots a line. What color will the line be?
Matplotlib
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [4, 5, 6], color='green') plt.show()
Attempts:
2 left
💡 Hint
The color is set by the 'color' parameter in plt.plot.
✗ Incorrect
The line color is set to 'green' explicitly by the color='green' argument.
❓ Predict Output
intermediateWhat is the width of the line plotted?
Check the code below. What is the width of the line shown in the plot?
Matplotlib
import matplotlib.pyplot as plt plt.plot([0, 1, 2], [2, 3, 4], linewidth=5) plt.show()
Attempts:
2 left
💡 Hint
The linewidth parameter controls the thickness of the line.
✗ Incorrect
The linewidth is set to 5 by the linewidth=5 argument.
🔧 Debug
advancedWhy does this code raise an error?
This code tries to plot a red line with width 3 but raises an error. What is the cause?
Matplotlib
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [3, 2, 1], color='red', linewidth=3) plt.show()
Attempts:
2 left
💡 Hint
String values must be in quotes in Python.
✗ Incorrect
The color argument value red is not quoted, so Python treats it as a variable which is not defined.
❓ data_output
advancedWhat is the RGB color code for the line?
The code below plots a line with color='cyan'. What is the RGB tuple for this color?
Matplotlib
import matplotlib.pyplot as plt line = plt.plot([0, 1], [1, 0], color='cyan') plt.show()
Attempts:
2 left
💡 Hint
Cyan is a mix of green and blue at full intensity.
✗ Incorrect
In RGB, cyan is (0, 1, 1) meaning no red, full green, full blue.
🚀 Application
expertHow to plot two lines with different colors and widths?
You want to plot two lines on the same graph: one red line with width 2, and one blue line with width 4. Which code does this correctly?
Attempts:
2 left
💡 Hint
Use color= and linewidth= parameters correctly.
✗ Incorrect
Options A and D use correct parameter names and values ('color' or its alias 'c'). Option B passes positional arguments incorrectly. Option C uses 'width' which is invalid.
