# 【2.2】matplotlib-hist(柱形图)

from numpy.random import normal
gaussian_numbers = normal(size=1000)
import matplotlib.pyplot as plt
from numpy.random import normal
gaussian_numbers = normal(size=1000)
plt.hist(gaussian_numbers)
plt.title("Gaussian Histogram")
plt.xlabel("Value")
plt.ylabel("Frequency")
plt.show()


#因为histogram默认是生成10个bin，有时候我们觉得区分细度不够的时候，可以人为来增加bin

plt.hist(gaussian_numbers, bins=20)
plt.show()


#我们也可以将纵坐标的频数转换成频率

plt.hist(gaussian_numbers, bins=20, normed=True)
plt.show()


#作累积概率分布图（cumulative distribution）

plt.hist(gaussian_numbers, bins=20, normed=True, cumulative=True)
plt.show()


#指定bin的横坐标范围

plt.hist(gaussian_numbers, bins=(-10,-1,1,10))
plt.show()


#未填充的bar

plt.hist(gaussian_numbers, bins=20, histtype='step')
plt.show()


## 二、更高级的用法

### 2.1 两个bar图的重叠

import matplotlib.pyplot as plt
from numpy.random import normal, uniform
gaussian_numbers = normal(size=1000)
uniform_numbers = uniform(low=-3, high=3, size=1000)
plt.hist(gaussian_numbers, bins=20, histtype='stepfilled', normed=True, color='b', label='Gaussian')
plt.hist(uniform_numbers, bins=20, histtype='stepfilled', normed=True, color='r', alpha=0.5, label='Uniform')
plt.title("Gaussian/Uniform Histogram")
plt.xlabel("Value")
plt.ylabel("Probability")
plt.legend()
plt.show()


## 参考资料：

https://bespokeblog.wordpress.com/2011/07/11/basic-data-plotting-with-matplotlib-part-3-histograms/