We can plot Gaussian distribution easily using Python. In this article, we will discuss how to plot normal distribution using matplotlib module in Python.
To plot the normal distribution, we will first generate evenly spaced numbers within a specific range. The following piece of Python code will generate evenly spaced 100 numbers within the range [-3, 3].
from numpy import linspace X = linspace(-3, 3, 100)
Please note that the generated numbers may include the endpoint (here 3) depending on whether the endpoint parameter of the linspace() function is True or not. If no value is given, then the endpoint parameter is by default True, and it includes the endpoint of the range.
After generating evenly spaced numbers on the X-axis, we need to generate numbers on the Y-axis as per the Gaussian distribution. To do so, we can use the norm.pdf() function.
from numpy import linspace from scipy.stats import norm X = linspace(-3, 3, 100) Y = norm.pdf(X)
By default, the probability density function norm.pdf() takes the mu to be 0 and the standard deviation to be 1. So, the above code will generate Y values corresponding to the given X values as per the standard normal distribution.
Now, we can use the matplotlib module to plot the standard normal distribution in the following way:






0 Comments