Recall & Review
beginner
What is the purpose of the
title() function in matplotlib?The
title() function adds a title to the top of the plot, helping to explain what the plot is about.Click to reveal answer
beginner
How do you add a label to the x-axis in a matplotlib plot?
Use the
xlabel() function with a string argument to name the x-axis, like plt.xlabel('Time (seconds)').Click to reveal answer
beginner
Which matplotlib function is used to label the y-axis?
The
ylabel() function is used to add a label to the y-axis, for example plt.ylabel('Temperature (°C)').Click to reveal answer
beginner
Why is it important to add labels and titles to your plots?
Labels and titles make plots easier to understand by explaining what data is shown and what each axis represents, just like signs help you understand a map.
Click to reveal answer
beginner
Show the matplotlib code to create a plot with title 'Sales Over Time', x-axis label 'Month', and y-axis label 'Sales ($)'.
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4], [10, 20, 25, 30])
plt.title('Sales Over Time')
plt.xlabel('Month')
plt.ylabel('Sales ($)')
plt.show()Click to reveal answer
Which function adds a title to a matplotlib plot?
✗ Incorrect
The
title() function sets the title of the plot.How do you label the y-axis in matplotlib?
✗ Incorrect
Use
ylabel() to add a label to the y-axis.What does
xlabel('Time') do in a plot?✗ Incorrect
xlabel() sets the label for the x-axis.Why should you add axis labels to a plot?
✗ Incorrect
Axis labels help viewers understand the data shown on each axis.
Which of these is NOT a function to add text labels in matplotlib?
✗ Incorrect
plot() draws data points; it does not add text labels.Explain how to add a title and axis labels to a matplotlib plot and why it is useful.
Think about how titles and labels help someone reading your plot.
You got /4 concepts.
Write a short matplotlib code snippet that creates a simple line plot with a title and labels for both axes.
Start with plotting data, then add title and labels, finally show the plot.
You got /5 concepts.