0
0
Matplotlibdata~15 mins

Bin count and bin edges in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Bin count and bin edges
📖 Scenario: You work as a data analyst for a small retail company. You have collected the daily sales amounts for a week. You want to understand how these sales amounts are distributed by grouping them into bins.
🎯 Goal: Build a simple Python program that uses matplotlib to calculate the count of sales amounts in each bin and the edges of these bins.
📋 What You'll Learn
Create a list called sales with the exact daily sales amounts given.
Create a variable called bins with the exact bin edges given.
Use matplotlib.pyplot.hist with bins and density=False to get the counts and bin edges.
Print the counts and bin edges exactly as shown.
💡 Why This Matters
🌍 Real World
Grouping data into bins helps businesses understand patterns, like how many sales fall into certain ranges.
💼 Career
Data analysts and scientists often use binning to summarize and visualize data distributions for reports and decision-making.
Progress0 / 4 steps
1
Create the sales data list
Create a list called sales with these exact daily sales amounts: 23, 45, 12, 67, 34, 89, 55.
Matplotlib
Need a hint?

Use square brackets to create a list and separate numbers with commas.

2
Create the bins variable
Create a list called bins with these exact bin edges: 0, 20, 40, 60, 80, 100.
Matplotlib
Need a hint?

Bins are the edges that separate the groups. Use a list with the exact numbers.

3
Calculate counts and bin edges using matplotlib
Import matplotlib.pyplot as plt. Use plt.hist with sales and bins, and set density=False. Assign the returned counts to counts and bin edges to edges.
Matplotlib
Need a hint?

Use import matplotlib.pyplot as plt and call plt.hist with the correct arguments.

4
Print the counts and bin edges
Print the counts array and the edges array exactly as they are.
Matplotlib
Need a hint?

Use two print statements: one for counts and one for edges.