Challenge - 5 Problems
Label Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the title of the plot?
Consider this code that creates a simple plot with matplotlib. What will be the title shown on the plot?
Matplotlib
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [4, 5, 6]) plt.title('Sales Over Time') plt.xlabel('Month') plt.ylabel('Revenue') plt.show()
Attempts:
2 left
💡 Hint
Look for the function that sets the main heading of the plot.
✗ Incorrect
The plt.title() function sets the main title of the plot. Here, it is set to 'Sales Over Time'.
❓ Predict Output
intermediate2:00remaining
What label appears on the y-axis?
Look at this code snippet. What label will appear on the y-axis of the plot?
Matplotlib
import matplotlib.pyplot as plt plt.plot([10, 20, 30], [1, 4, 9]) plt.xlabel('Time (s)') plt.ylabel('Distance (m)') plt.title('Motion Data') plt.show()
Attempts:
2 left
💡 Hint
The y-axis label is set by the function that starts with 'ylabel'.
✗ Incorrect
The plt.ylabel() function sets the label for the y-axis. Here, it is 'Distance (m)'.
🔧 Debug
advanced2:00remaining
Why does this code not show the x-axis label?
This code is supposed to show a plot with an x-axis label, but the label does not appear. What is the reason?
Matplotlib
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [3, 2, 1]) plt.xlabel('Time') plt.title('Sample Plot') plt.show()
Attempts:
2 left
💡 Hint
Check the order of commands and what plt.show() does.
✗ Incorrect
The plt.xlabel() is called before plt.show(), so the label 'Time' will appear on the x-axis. The code is correct.
❓ visualization
advanced2:00remaining
Identify the axis labels and title from the plot
Given this code, what are the x-axis label, y-axis label, and title of the plot?
Matplotlib
import matplotlib.pyplot as plt x = [0, 1, 2, 3] y = [0, 1, 4, 9] plt.plot(x, y) plt.xlabel('Input') plt.ylabel('Output') plt.title('Quadratic Growth') plt.show()
Attempts:
2 left
💡 Hint
Look at the functions plt.xlabel(), plt.ylabel(), and plt.title().
✗ Incorrect
plt.xlabel('Input') sets the x-axis label, plt.ylabel('Output') sets the y-axis label, and plt.title('Quadratic Growth') sets the plot title.
🧠 Conceptual
expert2:00remaining
What happens if you call plt.xlabel() twice with different labels before plt.show()?
If you run this code, what will be the label shown on the x-axis?
Matplotlib
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [3, 2, 1]) plt.xlabel('First Label') plt.xlabel('Second Label') plt.title('Test Plot') plt.show()
Attempts:
2 left
💡 Hint
Think about what happens when you set the same property twice.
✗ Incorrect
Calling plt.xlabel() twice sets the label twice. The last call overwrites the first, so 'Second Label' is shown.