0
0
Pandasdata~30 mins

Plot customization (title, labels, figsize) in Pandas - Mini Project: Build & Apply

Choose your learning style9 modes available
Plot customization (title, labels, figsize)
📖 Scenario: You are working with sales data for a small store. You want to create a clear and nice-looking bar chart to show the sales of different products.
🎯 Goal: Create a bar plot using pandas and customize it by adding a title, axis labels, and setting the figure size to make the chart easy to understand and visually appealing.
📋 What You'll Learn
Create a pandas DataFrame with product names and sales numbers.
Set a variable for figure size as a tuple.
Use the DataFrame's plot method to create a bar chart with the specified figure size.
Add a title and labels for the x-axis and y-axis.
Print the plot to display the customized chart.
💡 Why This Matters
🌍 Real World
Customizing plots helps make data charts clear and easy to understand for reports or presentations.
💼 Career
Data scientists and analysts often create visualizations with titles and labels to communicate insights effectively.
Progress0 / 4 steps
1
Create the sales data DataFrame
Create a pandas DataFrame called sales_data with two columns: 'Product' and 'Sales'. Use these exact values: 'Apples', 'Bananas', 'Cherries', 'Dates' for products and 30, 45, 15, 10 for sales.
Pandas
Need a hint?

Use pd.DataFrame with a dictionary where keys are column names and values are lists of data.

2
Set the figure size for the plot
Create a variable called fig_size and set it to the tuple (8, 5) to define the width and height of the plot in inches.
Pandas
Need a hint?

Use parentheses to create a tuple for figure size, like (width, height).

3
Create the bar plot with customization
Use sales_data.plot.bar() to create a bar chart. Set x='Product', y='Sales', and figsize=fig_size. Then add a title 'Sales by Product', x-axis label 'Product', and y-axis label 'Number of Sales' using the plot's set_title, set_xlabel, and set_ylabel methods.
Pandas
Need a hint?

Assign the plot to a variable, then use set_title, set_xlabel, and set_ylabel to add text.

4
Display the customized plot
Write a print() statement to display the plot object.
Pandas
Need a hint?

Use print(plot) to show the plot object in the output.