0
0
Matplotlibdata~30 mins

Multiple time series comparison in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Multiple Time Series Comparison
📖 Scenario: You work as a data analyst for a small retail company. You have sales data for three different products over a week. Your manager wants to see how the sales of these products compare day by day in a single chart.
🎯 Goal: Create a line chart that compares the daily sales of three products over one week using matplotlib. You will prepare the sales data, set up the days of the week, plot all three products on the same graph with labels, and display the chart.
📋 What You'll Learn
Create a dictionary called sales_data with keys 'Product A', 'Product B', and 'Product C' and their daily sales as lists of integers.
Create a list called days with the days of the week from Monday to Sunday.
Use matplotlib.pyplot to plot the sales of all three products on the same line chart with appropriate labels and a legend.
Display the plot using plt.show().
💡 Why This Matters
🌍 Real World
Comparing multiple time series data visually helps businesses understand trends and make decisions, such as comparing sales of different products over time.
💼 Career
Data analysts and scientists often need to visualize and compare multiple data series to communicate insights clearly to stakeholders.
Progress0 / 4 steps
1
Create the sales data dictionary
Create a dictionary called sales_data with these exact entries: 'Product A' with sales [20, 22, 19, 24, 30, 28, 25], 'Product B' with sales [15, 18, 17, 20, 22, 21, 19], and 'Product C' with sales [10, 12, 11, 14, 16, 15, 13].
Matplotlib
Need a hint?

Use curly braces {} to create the dictionary and colons : to assign lists to each product key.

2
Create the days list
Create a list called days containing the days of the week as strings: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'].
Matplotlib
Need a hint?

Use square brackets [] to create the list and include all days as strings.

3
Plot the sales data
Import matplotlib.pyplot as plt. Use a for loop with variables product and sales to iterate over sales_data.items(). Inside the loop, plot days on the x-axis and sales on the y-axis with label product. Add a legend with plt.legend().
Matplotlib
Need a hint?

Remember to import matplotlib.pyplot as plt. Use plt.plot() inside the loop and add label=product. Call plt.legend() after the loop.

4
Display the plot
Use plt.show() to display the line chart comparing the sales of the three products over the week.
Matplotlib
Need a hint?

Call plt.show() to open the window with the line chart.