0
0
Matplotlibdata~30 mins

Multiple histograms overlay in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Multiple histograms overlay
📖 Scenario: You are analyzing the sales data of two different stores. You want to compare the distribution of daily sales amounts for both stores visually.
🎯 Goal: Create two lists of daily sales amounts for Store A and Store B. Then, overlay their histograms on the same plot to compare their sales distributions.
📋 What You'll Learn
Create two lists named store_a_sales and store_b_sales with given sales data.
Create a variable bins to set the number of bins for the histograms.
Use matplotlib.pyplot.hist to plot both histograms on the same figure with transparency.
Add a legend to distinguish Store A and Store B histograms.
Display the plot using plt.show().
💡 Why This Matters
🌍 Real World
Overlaying histograms helps compare distributions of data from different groups, like sales from different stores or test scores from different classes.
💼 Career
Data scientists often compare multiple datasets visually to find patterns or differences, making histogram overlays a useful skill.
Progress0 / 4 steps
1
Create sales data lists
Create two lists called store_a_sales and store_b_sales with these exact values: store_a_sales = [20, 35, 30, 35, 27, 25, 32] and store_b_sales = [25, 32, 34, 20, 25, 40, 38].
Matplotlib
Need a hint?

Use square brackets to create lists with the exact numbers given.

2
Set number of bins for histograms
Create a variable called bins and set it to 5 to define the number of bins for the histograms.
Matplotlib
Need a hint?

Just assign the number 5 to a variable named bins.

3
Plot the histograms overlay
Import matplotlib.pyplot as plt. Use plt.hist to plot store_a_sales and store_b_sales on the same figure with bins bins, set alpha=0.5 for transparency, and add labels 'Store A' and 'Store B' respectively. Then add a legend with plt.legend().
Matplotlib
Need a hint?

Use plt.hist() twice with the correct parameters and then call plt.legend().

4
Show the plot
Add a line to display the plot using plt.show().
Matplotlib
Need a hint?

Use plt.show() to display the histogram plot window.