绘制直方图
2017-09-10 本文已影响34人
b485c88ab697
练习:绘制直方图
#coding:utf-8
#/usr/bin/python
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
if __name__ == '__main__':
mpl.rcParams['font.sans-serif'] = [u'SimHei']
mpl.rcParams['axes.unicode_minus'] = False # win正常显示中文设置
mu = 2
sigma = 3
data = mu + sigma * np.random.randn(1000)
h = plt.hist(data, 30, normed=1, color='#FFFFA0')
x = h[1]
y = norm.pdf(x, loc=mu, scale=sigma) #概率密度函数
plt.plot(x, y, 'r-', x, y, 'ro', linewidth=2, markersize=4)
plt.grid()
plt.show()