How to plot a normal distribution with Matplotlib in Python ?
Normal Distribution is a probability function used in statistics that tells about how the data values are distributed. It is the most important probability distribution function used in statistics because of its advantages in real case scenarios. For example, the height of the population, shoe size, IQ level, rolling a die, and many more.
The probability density function of normal or Gaussian distribution is given by:
Where, x is the variable, mu is the mean, and sigma standard deviation
- Matplotlib is python’s data visualization library which is widely used for the purpose of data visualization.
- Numpy is a general-purpose array-processing package. It provides a high-performance multidimensional array object, and tools for working with these arrays. It is the fundamental package for scientific computing with Python.
- Scipy is a python library that is useful in solving many mathematical equations and algorithms.
- Statistics module provides functions for calculating mathematical statistics of numeric data.
- To calculate mean of the data
- To calculate standard deviation of the data
- To calculate normal probability density of the data norm.pdf is used, it refers to the normal probability density function which is a module in scipy library that uses the above probability density function to calculate the value.
norm.pdf(Data, loc, scale)
Here, loc parameter is also known as the mean and the scale parameter is also known as standard deviation.
- Import module
- Create data
- Calculate mean and deviation
- Calculate normal probability density
- Plot using above calculated values
- Display plot
Below is the implementation.