# Multiple curves in one plot
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as stats
#------------------------------------------------------------
# control the parameter settings
= [-2, 0, 2]
mu_values = ['-', '--', '-.']
linestyles = ['black', 'red', 'blue']
colors
#------------------------------------------------------------
# plot the distributions
= plt.subplots(figsize=(10, 7))
fig, ax
for m, ls, cl in zip(mu_values, linestyles, colors):
= stats.norm.rvs(loc = m, scale = 1, size = 10000)
x = np.sort(x)
x1 = m, scale = 1), ls=ls, c=cl,
plt.plot(x1, stats.norm.pdf(x1, loc =r'$\mu=%.1f,\ \sigma^2=%.1f$' % (m,1))
label
-5, 5)
plt.xlim(0, 0.5)
plt.ylim(
'$x$')
plt.xlabel(r'$f(x|\mu)$')
plt.ylabel('Normal Distribution (mu changes, sigma fixed)')
plt.title(=1)
plt.legend(loc plt.show()
Lab 01
Special Continuous Distributions
Normal Distribution
# Multiple curves in one plot
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as stats
#------------------------------------------------------------
# control the parameter settings
# takes std as input argument, not variance
= [1, 2, 3]
sigma_values = ['-', '--', '-.']
linestyles = ['black', 'red', 'blue']
colors
#------------------------------------------------------------
# plot the distributions
= plt.subplots(figsize=(7, 7))
fig, ax
for s, ls, cl in zip(sigma_values, linestyles, colors):
= stats.norm.rvs(loc = 0, scale = s, size = 10000)
x = np.sort(x)
x1 = 0, scale = s), ls=ls, c=cl,
plt.plot(x1, stats.norm.pdf(x1, loc =r'$\mu=%.1f,\ \sigma^2=%.1f$' % (0,s*s))
label
-20, 20)
plt.xlim(0, 0.5)
plt.ylim(
'$x$')
plt.xlabel(r'$f(x|\sigma^2)$')
plt.ylabel('Normal Distribution (mu fixed, sigma2 changes)')
plt.title(=0)
plt.legend(loc plt.show()