banner



How To Draw A Bell Curve

A bell-shaped curve in statistics corresponds to a normal distribution or a Gaussian distribution which has been named subsequently High german mathematician Carl Friedrich Gauss. In a normal distribution, the points are full-bodied on the mean values and most of the points prevarication near the mean. The orientation of the bell-curve depends on the hateful and standard deviation values of a given fix of input points. By irresolute the value of the mean we can shift the location of the curve on the axis and the shape of the bend tin can be manipulated past irresolute the standard deviation values. In this article, we volition learn to plot a bong curve in Python.

In a normal distribution, mean, median, and mode are all equal and the bong-shaped bend is symmetric about the hateful i.e., the y-axis. The probability density function for a normal distribution is calculated using the formula:

f(x,\mu,\sigma ) = \frac{1}{\sigma\sqrt{2\pi}} \times e^{\frac{-1}{2}\times(\frac{x-u}{\sigma})^2}

Where:

x = input points,

\mu = mean

\sigma = standard deviation of the set of input values

Example 1: Creating  unproblematic bong curve.

Approach: We will make a list of points on the x-centrality and passed these points inside our custom pdf function to generate a probability distribution function to produce y-values respective to each point in x. Now we plot the curve using plot() and scatter() methods that are available in the matplotlib library. plot() method is used to make line plot and besprinkle() method is used to create dotted points inside the graph.

Code:

Python

import numpy every bit np

import matplotlib.pyplot as plt

def pdf(x):

mean = np.mean(x)

std = np.std(x)

y_out = 1 / (std * np.sqrt( ii * np.pi)) * np.exp( - (ten - mean) * * 2 / ( 2 * std * * 2 ))

render y_out

10 = np.arange( - 2 , 2 , 0.1 )

y = pdf(ten)

plt.style.utilise( 'seaborn' )

plt.figure(figsize = ( 6 , half dozen ))

plt.plot(x, y, colour = 'blackness' ,

linestyle = 'dashed' )

plt.scatter( 10, y, marker = 'o' , southward = 25 , colour = 'cherry' )

plt.prove()

Output:

Bong-shaped curve

Example 2: Fill the area under the bell curve.

We can as well make full in the surface area nether the bong-curve, for that nosotros are going to apply the fill_between() office present in the matplotlib library to colorize the surface area in-between 2 curves.

The fill_between() function accepts multiple parameters such as x-values, y-values which are coordinates of points and lines on the graph. Also, information technology supports some graph-specific parameters such equally 'alpha' which decides the opacity of color and the 'color' attribute accepts the name of the color to filled under the curve.

Approach: Nosotros took a list of points on the x-axis and passed these points inside our custom pdf part to generate a probability distribution office to produce y-values respective to each point in 10. Similarly, to fill in the area under the bend, we select a range of x_fill values and generate probability distribution too. At present we plot the curve first using plot() and scatter() method and fill the area under the curve with the fill_between() method.

Lawmaking:

Python

import numpy as np

import matplotlib.pyplot as plt

def pdf(x):

mean = np.mean(x)

std = np.std(x)

y_out = 1 / (std * np.sqrt( 2 * np.pi)) * np.exp( - (x - mean) * * two / ( ii * std * * ii ))

return y_out

x = np.arange( - 2 , two , 0.1 )

y = pdf(10)

x_fill = np.arange( - ii , two , 0.i )

y_fill = pdf(x_fill)

plt.style.use( 'seaborn' )

plt.figure(figsize = ( vi , vi ))

plt.plot(x, y, colour = 'black' ,

linestyle = 'dashed' )

plt.besprinkle(x, y, marker = 'o' ,

s = 25 , color = 'red' )

plt.fill_between(x_fill, y_fill, 0 ,

alpha = 0.ii , color = 'bluish' )

plt.bear witness()

Output:

Plot displaying the filled surface area under the bell-bend


Source: https://www.geeksforgeeks.org/how-to-make-a-bell-curve-in-python/

Posted by: rondonsecandent.blogspot.com

0 Response to "How To Draw A Bell Curve"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel