Hackerss.com is a community of amazing hackers

Hackerss is a community for developers, data scientitst, ethical hackers, hardware enthusiasts or any person that want to learn / share their knowledge of any aspect of digital technology.

Create account Log in

Posted on

Plot a normal distribution in Python

Plot a normal distribution - Python:

import matplotlib.pyplot as plt
import numpy as np

def plot_normal_distribution(mean, std):
    Plot a normal distribution.

    mean : float
        Mean of the normal distribution.
    std : float
        Standard deviation of the normal distribution.

        The function plots the normal distribution and does not return anything.

    #create a range of x values from -4σ to 4σ with 0.01 increments
    x = np.arange(mean - 4*std, mean + 4*std, 0.01)

    #calculate the y values corresponding to the x values
    y = (1/(std * np.sqrt(2 * np.pi))) * np.exp(-0.5 * ((x - mean)/std)**2)

    #plot the x and y values
    plt.plot(x, y)

    #show the plot

plot_normal_distribution(0, 1)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)