9 正态分布图

import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm
plt.rcParams['text.usetex'] = False
mu, sigma = 0, 1

x = np.linspace(mu - 3sigma, mu + 3sigma, 100)

y = norm.pdf(x, mu, sigma)

plt.figure(figsize=(8, 6))
plt.plot(x, y, 'r-', lw=2, label=f'Normal distribution\n\(\mu={mu}\), \(\sigma={sigma}\)')
plt.fill_between(x, y, where=(x > mu - sigma) & (x < mu + sigma), facecolor='blue', alpha=0.3, interpolate=True)
plt.fill_between(x, y, where=(x > mu - 2sigma) & (x < mu + 2sigma), facecolor='blue', alpha=0.1, interpolate=True)
plt.fill_between(x, y, where=(x > mu - 3sigma) & (x < mu + 3sigma), facecolor='blue', alpha=0.05, interpolate=True)
plt.title('Normal Distribution')
plt.xlabel('Value')
plt.ylabel('Probability Density')
plt.legend(loc='upper left')
plt.grid(True)
plt.show()

print("学号后两位:04")

posted on 2024-11-26 14:32  黄元元  阅读(8)  评论(0编辑  收藏  举报