Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
高斯正态分布用matplotlib画直方图
#!/usr/bin/env python
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
import pdb
mu, sigma = 100, 15
x = mu + sigma*np.random.randn(10000)
pdb.set_trace()
# the histogram of the data
# normed表示直方图规范化总面积为1,alpha表示透明度
n, bins, patches = plt.hist(x, 50, normed=1, facecolor='green', alpha=0.75)
# add a 'best fit' line
# normpdf表示在bins的每个点上用mu,sigma参数画出对应的正态点
y = mlab.normpdf( bins, mu, sigma)
z = mlab.normpdf( bins, mu, 10)
l = plt.plot(bins, y, 'r--', linewidth=1)
v = plt.plot(bins, z, 'bo', linewidth=3)
plt.xlabel('Smarts')
plt.ylabel('Probability')
plt.title(r'$\mathrm{Histogram\ of\ IQ:}\ \mu=100,\ \sigma=15$')
plt.axis([40, 160, 0, 0.03])
plt.grid(True)
plt.show()
@guori12321
Copy link

guori12321 commented May 27, 2013

"#coding=utf-8" are required at the beginning, otherwise your note in Chinese won't be recongized.

Loading

@guori12321
Copy link

guori12321 commented May 27, 2013

"#coding=utf-8" are required at the beginning, otherwise your note in Chinese won't be recongized.

Loading

@shuivin
Copy link
Author

shuivin commented Oct 21, 2019

test

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment