Chapter 2 - part 2 - (Histogram)
Chapter 2 - part 2 - (Histogram)
Histogram
A histogram is a powerful technique in data visualization.
To construct a histogram:
The bins (intervals) must be adjacent, and are often (but are not
required to be) of equal size.
1
7/27/2024
2
7/27/2024
Total 20 readings are there in the list h, which is given as the argument of hist()
By default, there will be 10 classes or bins.
(180-150)/10 = 30/10 = 3 is taken as the class width
Classes: 150-153, 153-156,…, 177-180 is represented on the X-axis
No. of readings in each class (frequency) is represented on the Y axis
3
7/27/2024
4
7/27/2024
5
7/27/2024
bins
weights
label
orientation
align
edgecolor
facecolor
6
7/27/2024
bins parameter
bins parameter can be int or sequence
If bins is an integer, it defines the number of equal-width bins
in the range. (default: 10)
If bins is a sequence, it defines the bin edges.
In this case, bins may be unequally spaced.
All except the last (right hand-most) bin is half-open. i.e.,
Except last bin, all bins includes the left edge but excludes the
right edge.
In other words, if bins = [1, 2, 3, 4] then the first bin
is includes 1, but excludes 2. The second includes 2, but
excludes 3. The last bin, however, includes both 3 and 4.
• Number of values in
variables dt and wt should
match.
7
7/27/2024
weights parameter
It is an array of weights, of the same shape as x (let x be the
list of data items)
Each value in x only contributes its associated weight
towards the bin count.
This parameter can be used to draw a histogram of data
that has already been binned (by treating each bin as a
single point with a weight equal to its count)
align parameter
8
7/27/2024
9
7/27/2024
SAVING FIGURE
matplotlib.pyplot.savefig(“filenamewithpath”)
• For example:To save a figure in D drive as pchart
plt.savefig(“D:\\pchart.png”) OR plt.savefig(“D:/pchart.png”)
• Or you can click the save button on the GUI panel
• The file will be saved in the python folder.
10
7/27/2024
Answer :
11
7/27/2024
Answer :
12
7/27/2024
Types of histograms
1. Simple(vertical) histogram
2. Horizontal histogram
[orientation=‘horizontal’]
3. Step type histogram / frequency polygon
[histtype=“step”]
4. Cumulative histogram
[cumulative=True]
13
7/27/2024
CUMULATIVE HISTOGRAM
The cumulative histogram is a histogram in which the vertical axis
gives not just the counts for a single bin, but rather gives the total
count of that bin and all bins before it
14
7/27/2024
a) Simple histogram
15
7/27/2024
b) Horizontal histogram
16
7/27/2024
d)Cumulative histogram
QN 24)
A list namely temp contains average
temperature for seven days of last week. you
want to see how the temperature changes in
last 7 days. Which chart type will you plot for
the same and why?
17
7/27/2024
Qn. 34)
kritika was asked to write the names of a few libraries in python used
for data analysis and one method of each . Help her write at least 3
libraries and their methods.
Libraries Methods
18