Created
October 25, 2019 01:06
-
-
Save albertyumol/1ca016de3af5047f24dab392f3b5390f to your computer and use it in GitHub Desktop.
Plotting normal pdf's in Python.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
def normal_pdf(x, mu=0, sigma=1): | |
sqrt_two_pi = np.sqrt(2*np.pi) | |
return (np.exp(-(x-mu)**2/2/sigma**2)/(sqrt_two_pi*sigma)) | |
xs = [x / 10.0 for x in range(-50, 50)] | |
plt.plot(xs, [normal_pdf(x, sigma=1) for x in xs], '-', label='$\mu=0$, $\sigma=1$') | |
plt.plot(xs, [normal_pdf(x, sigma=2) for x in xs], '--', label='$\mu=0$, $\sigma=2$') | |
plt.plot(xs, [normal_pdf(x, sigma=0.5) for x in xs], ':', label='$\mu=0$, $\sigma=0.5$') | |
plt.plot(xs, [normal_pdf(x, mu=-1) for x in xs], '-.', label='$\mu=-1$, $\sigma=1$') | |
plt.legend() | |
plt.xlim(-5,5) | |
plt.title('Various Normal pdf\'s') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment