0
0
Matplotlibdata~15 mins

Title and axis labels in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Title and axis labels
📖 Scenario: You are analyzing sales data for a small store. You want to create a simple line chart to show how sales changed over a week.
🎯 Goal: Create a line chart using matplotlib with a title and labels for the x-axis and y-axis to clearly explain the chart.
📋 What You'll Learn
Create a list called days with the days of the week from Monday to Sunday.
Create a list called sales with the sales numbers for each day: 150, 200, 170, 220, 180, 190, 210.
Use matplotlib.pyplot to plot the sales data as a line chart.
Add a chart title using plt.title() with the text 'Weekly Sales'.
Add an x-axis label using plt.xlabel() with the text 'Day of the Week'.
Add a y-axis label using plt.ylabel() with the text 'Sales (units)'.
Display the chart using plt.show().
💡 Why This Matters
🌍 Real World
Adding titles and axis labels helps anyone looking at your charts understand what the data means quickly.
💼 Career
Data scientists and analysts always label their charts clearly to communicate insights effectively to others.
Progress0 / 4 steps
1
Create the sales data lists
Create a list called days with these exact values: 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'. Then create a list called sales with these exact values: 150, 200, 170, 220, 180, 190, 210.
Matplotlib
Need a hint?

Use square brackets to create lists. Separate items with commas.

2
Import matplotlib and prepare to plot
Import matplotlib.pyplot as plt. This will let you create charts easily.
Matplotlib
Need a hint?

Use the import statement to bring in matplotlib.pyplot and rename it as plt.

3
Plot the sales data with title and axis labels
Use plt.plot(days, sales) to create a line chart. Then add a title with plt.title('Weekly Sales'). Add an x-axis label with plt.xlabel('Day of the Week') and a y-axis label with plt.ylabel('Sales (units)').
Matplotlib
Need a hint?

Use plt.plot() to draw the line. Use plt.title(), plt.xlabel(), and plt.ylabel() to add text.

4
Display the chart
Use plt.show() to display the chart with the title and axis labels.
Matplotlib
Need a hint?

Call plt.show() to see the chart window pop up.