Normal Distribution Plot using Numpy and Matplotlib
Last Updated :
30 Jul, 2024
In this article, we will see how we can create a normal distribution plot in python with numpy and matplotlib module.
What is Normal Distribution?
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.
It is generally observed that data distribution is normal when there is a random collection of data from independent sources. The graph produced after plotting the value of the variable on x-axis and count of the value on y-axis is bell-shaped curve graph. The graph signifies that the peak point is the mean of the data set and half of the values of data set lie on the left side of the mean and other half lies on the right part of the mean telling about the distribution of the values. The graph is symmetric distribution.
Modules Needed
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.
Besides its obvious scientific uses, Numpy can also be used as an efficient multi-dimensional container of generic data.
Matplotlib is a plotting library for creating static, animated, and interactive visualizations in Python. Matplotlib can be used in Python scripts, the Python and IPython shell, web application servers, and various graphical user interface toolkits like Tkinter, awxPython, etc.
Below are some program which create a Normal Distribution plot using Numpy and Matplotlib module:
Example 1:
Python3
# importing numpy as np
import numpy as np
# importing pyplot as plt
import matplotlib.pyplot as plt
# position
pos = 100
# scale
scale = 5
# size
size = 100000
# creating a normal distribution data
values = np.random.normal(pos, scale, size)
# plotting histograph
plt.hist(values, 100)
# showing the graph
plt.show()
Output :

Example 2:
Python3
# importing numpy as np
import numpy as np
# importing pyplot as plt
import matplotlib.pyplot as plt
# position
pos = 0
# scale
scale = 10
# size
size = 10000
# random seed
np.random.seed(10)
# creating a normal distribution data
values = np.random.normal(pos, scale, size)
# plotting histograph
plt.hist(values, 100)
# plotting mean line
plt.axvline(values.mean(), color='k', linestyle='dashed', linewidth=2)
# showing the plot
plt.show()
Output :
Similar Reads
How to plot a normal distribution with Matplotlib in Python? Normal distribution, also known as the Gaussian distribution, is a fundamental concept in probability theory and statistics. It is a symmetric, bell-shaped curve that describes how data values are distributed around the mean. The probability density function (PDF) of a normal distribution is given b
4 min read
Normal Distribution in NumPy The Normal Distribution also known as the Gaussian Distribution is one of the most important distributions in statistics and data science. It is widely used to model real-world phenomena such as IQ scores, heart rates, test results and many other naturally occurring events.numpy.random.normal() Meth
2 min read
Save Plot To Numpy Array using Matplotlib Saving a plot to a NumPy array in Python is a technique that bridges data visualization with array manipulation allowing for the direct storage of graphical plots as array representations, facilitating further computational analyses or modifications within a Python environment. Let's learn how to Sa
4 min read
Generate five random numbers from the normal distribution using NumPy In Numpy we are provided with the module called random module that allows us to work with random numbers. The random module provides different methods for data distribution. In this article, we have to create an array of specified shape and fill it random numbers or values such that these values are
2 min read
Python - Normal Distribution in Statistics A probability distribution determines the probability of all the outcomes a random variable takes. The distribution can either be continuous or discrete distribution depending upon the values that a random variable takes. There are several types of probability distribution like Normal distribution,
6 min read
Introduction to 3D Plotting with Matplotlib In this article, we will be learning about 3D plotting with Matplotlib. There are various ways through which we can create a 3D plot using matplotlib such as creating an empty canvas and adding axes to it where you define the projection as a 3D projection, Matplotlib.pyplot.gca(), etc. Creating an E
15+ min read