0
0
Matplotlibdata~15 mins

Basic histogram with plt.hist in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Basic histogram with plt.hist
📖 Scenario: You have collected the ages of a group of people at a community event. You want to see how these ages are spread out to understand the age distribution.
🎯 Goal: Build a simple histogram using plt.hist to visualize the distribution of ages.
📋 What You'll Learn
Create a list called ages with the exact values: 22, 25, 29, 22, 24, 30, 27, 25, 29, 31
Create a variable called bins and set it to 5
Use plt.hist with ages and bins to create the histogram
Use plt.show() to display the histogram
💡 Why This Matters
🌍 Real World
Histograms help us understand how data like ages, heights, or test scores are spread out in a group.
💼 Career
Data scientists use histograms to quickly see patterns and distributions in data, which helps in making decisions or building models.
Progress0 / 4 steps
1
Create the data list
Create a list called ages with these exact values: 22, 25, 29, 22, 24, 30, 27, 25, 29, 31
Matplotlib
Need a hint?

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

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

Just assign the number 5 to the variable bins.

3
Create the histogram
Import matplotlib.pyplot as plt and use plt.hist with ages and bins to create the histogram
Matplotlib
Need a hint?

Use import matplotlib.pyplot as plt to import. Then call plt.hist(ages, bins=bins).

4
Display the histogram
Use plt.show() to display the histogram
Matplotlib
Need a hint?

Call plt.show() after creating the histogram to see the plot.