0
0
Matplotlibdata~20 mins

Title and axis labels in Matplotlib - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Master of Titles and Labels
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
What is the title of the plot?
Look at the code below. 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 Data
BSales Over Time
CMonth
DRevenue
Attempts:
2 left
💡 Hint
The title is set by plt.title() function.
Predict Output
intermediate
1:30remaining
What is the label of the x-axis?
What label will appear on the x-axis in the plot below?
Matplotlib
import matplotlib.pyplot as plt
plt.plot([10, 20, 30], [1, 4, 9])
plt.title('Growth Chart')
plt.xlabel('Time (years)')
plt.ylabel('Value')
plt.show()
AGrowth Chart
BValue
CTime (years)
DYears
Attempts:
2 left
💡 Hint
The x-axis label is set by plt.xlabel().
🔧 Debug
advanced
2:00remaining
Why does this code not show the y-axis label?
The code below is supposed to show a y-axis label, but it does not appear. What is the problem?
Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [3, 2, 1])
plt.title('Sample Plot')
plt.xlabel('X Axis')
plt.ylabel('')
plt.show()
AThe y-axis label is empty, so nothing shows.
Bplt.ylabel() is missing parentheses.
Cplt.title() must be called after plt.ylabel().
DThe plot() function must include label parameter.
Attempts:
2 left
💡 Hint
Check the argument passed to plt.ylabel().
data_output
advanced
2:00remaining
What are the axis labels after this code?
After running the code below, what are the labels of the x-axis and y-axis?
Matplotlib
import matplotlib.pyplot as plt
plt.plot([5, 10, 15], [2, 4, 6])
plt.xlabel('Distance (km)')
plt.ylabel('Speed (km/h)')
plt.xlabel('Time (seconds)')
plt.show()
Ax-axis: 'Time (seconds)', y-axis: 'Speed (km/h)'
Bx-axis: 'Distance (km)', y-axis: 'Speed (km/h)'
Cx-axis: 'Distance (km)', y-axis: ''
Dx-axis: '', y-axis: 'Speed (km/h)'
Attempts:
2 left
💡 Hint
The last plt.xlabel() call overwrites the previous one.
🧠 Conceptual
expert
1:30remaining
Why is it important to label axes and add titles in plots?
Choose the best reason why adding titles and axis labels is important in data visualization.
AThey allow the plot to run faster in Python.
BThey make the plot look colorful and attractive.
CThey increase the file size of the plot image.
DThey help viewers understand what the data and axes represent.
Attempts:
2 left
💡 Hint
Think about how someone else reads your plot.