Recall & Review
beginner
What function in matplotlib is used to add a title to a plot?
The
plt.title() function adds a title to the plot.Click to reveal answer
beginner
How do you label the x-axis in a matplotlib plot?
Use
plt.xlabel() to add a label to the x-axis.Click to reveal answer
beginner
How do you label the y-axis in a matplotlib plot?
Use
plt.ylabel() to add a label to the y-axis.Click to reveal answer
beginner
Why is it important to add titles and axis labels to your plots?
Titles and axis labels help people understand what the plot shows, making the data clear and easy to read.
Click to reveal answer
beginner
Show the code to create a simple line plot with title 'Sales Over Time', x-axis label 'Month', and y-axis label 'Sales'.
import matplotlib.pyplot as plt
months = [1, 2, 3, 4]
sales = [10, 15, 7, 12]
plt.plot(months, sales)
plt.title('Sales Over Time')
plt.xlabel('Month')
plt.ylabel('Sales')
plt.show()Click to reveal answer
Which matplotlib function adds a title to a plot?
✗ Incorrect
The
plt.title() function is used to add a title to the plot.How do you add a label to the x-axis in matplotlib?
✗ Incorrect
Use
plt.xlabel() to label the x-axis.What does
plt.ylabel('Temperature') do?✗ Incorrect
plt.ylabel() sets the label for the y-axis.Why should you add titles and axis labels to your plots?
✗ Incorrect
Titles and labels explain what the plot shows, helping viewers understand the data.
Which of these is the correct way to add a title and labels in matplotlib?
✗ Incorrect
The correct functions are
plt.title(), plt.xlabel(), and plt.ylabel().Explain how to add a title and axis labels to a matplotlib plot and why it is important.
Think about the functions used and the purpose of labels.
You got /5 concepts.
Write a short code snippet to create a plot with a title and labels for both axes.
Start with importing matplotlib, then plot, add title and labels, and finally show the plot.
You got /6 concepts.