Page 209 - Robotics and AI class 10
P. 209
plt.ylabel('Temp in Celsius')
plt.title('Temperature Study of the Day')
# Displaying the chart
plt.show()
Temperature Study of the Day
Day1
40 Day2
35 Day3
Temp in Celsius 30
25
20
15
10
5
0
Delhi Mumbai Chennai Kolkata
Metro Cities
Plotting a Histogram chart
It represents the frequency of the variable at different points of time. It is used for continuous data and the bars
created show no gap in between X-axis represents the bin ranges while Y-axis gives information about frequency.
A histogram displays the numerical data grouped into bars also known as “bins" of equal size. The height of the bar
represents the data point. Histogram helps you find the number of bars, the range of numbers that go into each
bar, and the labels for the bar edges.
Before you go for designing a Histogram you need to finalise the width of each bin. If we go from 10 to 250 using
bins with a width of 50 then the data can easily adjust in 5 bins. It is always a good practice of using a decent
number of bins in the designing of a histogram.
import matplotlib.pyplot as plt
# Number of schools in each city
schools = [10,25,29]
# Creating the histogram with bins
plt.his(schools, bins=[10,15,20,25,30])
# Adding labels and title
plt.xlabel('Number of Schools')
plt.ylabel('Frequency')
plt.title('Distribution of Schools in Cities')
# Customizing x-axis tick labels
plt.xticks(=[15, 20, 25, 30])
# Displaying the histogram
plt.show()
Introduction to Data and Programming with Python 207

