Plotting of 1-dimensional Gaussian distribution function

后端 未结 5 433
忘掉有多难
忘掉有多难 2021-02-04 01:09

How do I make plots of a 1-dimensional Gaussian distribution function using the mean and standard deviation parameter values (μ, σ) = (−1, 1), (0, 2), and (2, 3)?

I\'m n

5条回答
  •  天涯浪人
    2021-02-04 01:35

    With the excellent matplotlib and numpy packages

    from matplotlib import pyplot as mp
    import numpy as np
    
    def gaussian(x, mu, sig):
        return np.exp(-np.power(x - mu, 2.) / (2 * np.power(sig, 2.)))
    
    x_values = np.linspace(-3, 3, 120)
    for mu, sig in [(-1, 1), (0, 2), (2, 3)]:
        mp.plot(x_values, gaussian(x_values, mu, sig))
    
    mp.show()
    

    will produce something like

提交回复
热议问题