0
0
Data Analysis Pythondata~30 mins

Labels, titles, and legends in Data Analysis Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Labels, titles, and legends
📖 Scenario: You are analyzing sales data for a small store. You want to create a simple bar chart to show the sales of different products. To make the chart clear, you will add labels to the axes, a title, and a legend.
🎯 Goal: Create a bar chart using Python's matplotlib library that shows product sales. Add an x-axis label, a y-axis label, a chart title, and a legend to explain the colors.
📋 What You'll Learn
Create a dictionary called sales with product names as keys and sales numbers as values.
Create a variable called colors that assigns a color to each product.
Use matplotlib to plot a bar chart with the sales data.
Add an x-axis label called Product.
Add a y-axis label called Sales.
Add a chart title called Sales by Product.
Add a legend that shows which color belongs to which product.
💡 Why This Matters
🌍 Real World
Adding labels, titles, and legends to charts helps people understand data clearly. This is important when sharing reports or presentations.
💼 Career
Data scientists and analysts often create charts to explain their findings. Knowing how to label charts properly is a key skill for clear communication.
Progress0 / 4 steps
1
Create the sales data dictionary
Create a dictionary called sales with these exact entries: 'Apples': 30, 'Bananas': 45, 'Cherries': 25, 'Dates': 40.
Data Analysis Python
Hint

Use curly braces {} to create the dictionary with the exact keys and values.

2
Create the colors list
Create a list called colors with these exact values in order: 'red', 'yellow', 'pink', 'brown'.
Data Analysis Python
Hint

Use square brackets [] to create the list with the exact colors in the order of the products.

3
Plot the bar chart with labels, title, and legend
Import matplotlib.pyplot as plt. Use plt.bar() to plot the sales data with product names on the x-axis and sales numbers on the y-axis. Use the colors list for the bar colors. Add an x-axis label 'Product', a y-axis label 'Sales', and a title 'Sales by Product'. Add a legend that shows each product with its color.
Data Analysis Python
Hint

Use plt.bar() with color=colors. Use plt.xlabel(), plt.ylabel(), and plt.title() to add labels and title. Use plt.legend() with the bars and product names.

4
Display the chart
Use plt.show() to display the bar chart with labels, title, and legend.
Data Analysis Python
Hint

Call plt.show() to display the chart window.