0
0
Matplotlibdata~20 mins

Label, title, and axis names in Matplotlib - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Label Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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()
ASales
BRevenue
CSales Over Time
DMonth
Attempts:
2 left
💡 Hint
Look for the function that sets the main heading of the plot.
Predict Output
intermediate
2: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()
ATime (s)
BDistance (m)
CMotion Data
DSpeed (m/s)
Attempts:
2 left
💡 Hint
The y-axis label is set by the function that starts with 'ylabel'.
🔧 Debug
advanced
2: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()
AThe x-axis label is set correctly and will appear as 'Time'.
BThe plot command is missing, so no plot is shown.
CThe plt.xlabel() function is called after plt.show(), so it does not update the plot.
DThe x-axis label is not shown because plt.title() overrides it.
Attempts:
2 left
💡 Hint
Check the order of commands and what plt.show() does.
visualization
advanced
2: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()
Ax-axis: Input, y-axis: Output, title: Quadratic Growth
Bx-axis: Output, y-axis: Input, title: Quadratic Growth
Cx-axis: Input, y-axis: Quadratic Growth, title: Output
Dx-axis: Quadratic Growth, y-axis: Output, title: Input
Attempts:
2 left
💡 Hint
Look at the functions plt.xlabel(), plt.ylabel(), and plt.title().
🧠 Conceptual
expert
2: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()
ANo x-axis label will appear because of the conflict.
BThe x-axis label will be 'First Label'.
CBoth labels will appear on the x-axis.
DThe x-axis label will be 'Second Label'.
Attempts:
2 left
💡 Hint
Think about what happens when you set the same property twice.