0
0
Data Analysis Pythondata~30 mins

Subplots for multiple charts in Data Analysis Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Subplots for multiple charts
📖 Scenario: You work as a data analyst for a small store. You have sales data for two products over four months. You want to create two charts side by side to compare their sales trends easily.
🎯 Goal: Create two line charts side by side using subplots to show monthly sales for Product A and Product B.
📋 What You'll Learn
Create a dictionary called sales_data with monthly sales for Product A and Product B
Create a variable called months with the list of month names
Use plt.subplots() to create two side-by-side plots
Plot Product A sales on the first subplot and Product B sales on the second subplot
Add titles to each subplot: 'Product A Sales' and 'Product B Sales'
Display the plots side by side
💡 Why This Matters
🌍 Real World
Creating multiple charts side by side helps compare different data sets visually, which is common in business reports and presentations.
💼 Career
Data analysts and scientists often use subplots to present multiple related charts clearly and efficiently.
Progress0 / 4 steps
1
Create the sales data dictionary
Create a dictionary called sales_data with these exact entries: 'Product A': [150, 200, 250, 300] and 'Product B': [180, 210, 230, 280].
Data Analysis Python
Hint

Use curly braces {} to create the dictionary with keys 'Product A' and 'Product B' and their sales lists as values.

2
Create the months list
Create a list called months with these exact values: ['Jan', 'Feb', 'Mar', 'Apr'].
Data Analysis Python
Hint

Use square brackets [] to create the list of months in order.

3
Create subplots and plot the sales data
Import matplotlib.pyplot as plt. Use plt.subplots() to create two side-by-side plots stored in variables fig and axes. Plot months vs sales_data['Product A'] on axes[0] and months vs sales_data['Product B'] on axes[1]. Add titles 'Product A Sales' and 'Product B Sales' to the respective subplots.
Data Analysis Python
Hint

Use plt.subplots(1, 2) to create two plots side by side. Use axes[0].plot() and axes[1].plot() to plot each product's sales. Use set_title() to add titles.

4
Display the subplots
Add a line to display the plots using plt.show().
Data Analysis Python
Hint

Use plt.show() to display the figure with both subplots.