Page 299 - AI_Ver_3.0_class_11
P. 299
Histogram is the simplest method for visualising data distributions. For example:
Weights (in kg) Frequency (Number of students)
20-25 4
26-30 10
31-35 8
36-40 4
Program 7: Create a Histogram for number of hours students spend studying per week using Python Number:
[5, 7, 8, 10, 12, 14, 15, 16, 18, 20, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24]
This example takes number of hours per week that students spend in studying. To create a histogram from the given
data, we must first organise it into intervals. These intervals are frequently referred to as logical ranges or bins.
import matplotlib.pyplot as plt
# Sample data: number of hours students spend studying per week
study_hours = [5, 7, 8, 10, 12, 14, 15, 16, 18, 20,
9, 11, 13, 15, 17, 19, 21, 23, 25, 27,
6, 8, 10, 12, 14, 16, 18, 20, 22, 24]
# Create a histogram using hist() function
plt.hist(study_hours, bins=8, color='green')
# Add titles and labels
plt.title('Distribution of Study Hours per Week for Students in Class XII')
plt.xlabel('Study Hours per Week')
plt.ylabel('Frequency')
# Display the plot
plt.show()
Data Literacy—Data Collection to Data Analysis 297

