0% found this document useful (0 votes)
60 views10 pages

Histrogram: A Histogram Is A Graph Showing Frequency Distributions

A histogram is a graph that shows the distribution of numerical data by dividing the range of values into equal-sized bins and plotting the frequency of observations in each bin. It can be customized by changing attributes like the number of bins, colors, and adding additional plots on the same figure using subplots. Matplotlib's plt.hist() and plt.subplots() functions are commonly used to create and customize histograms with multiple plots.

Uploaded by

Gautam Sai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views10 pages

Histrogram: A Histogram Is A Graph Showing Frequency Distributions

A histogram is a graph that shows the distribution of numerical data by dividing the range of values into equal-sized bins and plotting the frequency of observations in each bin. It can be customized by changing attributes like the number of bins, colors, and adding additional plots on the same figure using subplots. Matplotlib's plt.hist() and plt.subplots() functions are commonly used to create and customize histograms with multiple plots.

Uploaded by

Gautam Sai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Histrogram

A histogram is a graph showing frequency distributions

It is a graph showing the number of observations within each given interval .


4 people from 190 to 195cm
Example: Say you ask for the height of 250 people, you might end up with a histogram like this

46 people from 163 to 168cm


31 people from 157 to 162cm
46 people from 163 to 168cm
53 people from 168 to 173cm
45 people from 173 to 178cm
28 people from 179 to 184cm
21 people from 185 to 190cm

15 people from 151 to 156cm

5 people from 145 to 150cm

2 people from 140 to 145cm


Histrogram
from matplotlib import pyplot as plt
import numpy as np

#Creating dataset
a = np.array([22, 87, 5, 43, 56,73, 55, 54, 11,20, 51, 5, 79, 31,27])

# Creating histogram

fig, ax = plt.subplots(figsize =(10, 7))


ax.hist(a, bins = [0, 25, 50, 75, 100])

# Show plot
plt.show()
 the results of rolling 2 dice
Only has the values 2, 3, 4, 5, 6, 7, 8,
9, 10, 11 and 12
Histogram
Histogram(subplot)
It is accurate method for the graphical representation of numerical data distribution.
.It is a type of bar plot where X-axis represents the bin ranges while Y-axis gives information about frequency.

Creating a Histogram

creates a figure and a grid of subplots with a single call

function takes three arguments that describes the layout of the figure.

The layout is organized in rows and columns, which are represented bythe first and second argument.

The third argument represents the index of the current plot.


plt.subplot(1, 2, 1) ----- #the figure has 1 row, 2 columns, and this plot is the first plot.plt.subplot

plot.plt.subplot(1, 2, 2)#the figure has 1 row, 2 columns, and this plot is the first plot.

subplots() without arguments returns a Figure and a single Axes.


supplot
Draw 2 plots on top of each other:
import matplotlib.pyplot as plt
import numpy as np

#plot 1:
x = np.array([0, 1, 2, 3])
y = np.array([3, 8, 1, 10])

plt.subplot(2, 1, 1)
plt.plot(x,y)

#plot 2:
x = np.array([0, 1, 2, 3])
y = np.array([10, 20, 30, 40])

plt.subplot(2, 1, 2)
plt.plot(x,y)

plt.show()
Histogram
Customization of Histogram
Matplotlib provides a range of different methods to customize histogram. 
matplotlib.pyplot.hist() function itself provides many attributes with the help of which we can modify a histogram

import matplotlib.pyplot as plt


import numpy as np

from matplotlib import colors


from matplotlib.ticker import PercentFormatter

# Creating dataset

np.random.seed(23685752)
N_points = 10000

n_bins = 20
x = np.random.randn(N_points) # Creating distribution
y = .8 ** x + np.random.randn(10000) + 25

fig, axs = plt.subplots(1, 1, figsize =(10, 7),tight_layout = True)

axs.hist(x, bins = n_bins) plt.show()


Histrogram
Multi-plot
import matplotlib.pyplot as plt

import numpy as np

# Some example data to display

x = np.linspace(0, 2 * np.pi, 400)

y = np.sin(x ** 2)

fig, ax = plt.subplots()

You might also like