numpy直方图和pylab直方图的比较

来源:互联网 发布:电脑硬盘测评软件 编辑:程序博客网 时间:2024/06/06 03:50

直方图(histogram)

NumPy中histogram函数应用到一个数组返回一对变量:直方图数组和箱式向量。注意:matplotlib也有一个用来建立直方图的函数(叫作hist,正如matlab中一样)与NumPy中的不同。主要的差别是pylab.hist自动绘制直方图,而numpy.histogram仅仅产生数据。

import numpyimport pylab# Build a vector of 10000 normal deviates with variance 0.5^2 and mean 2mu, sigma = 2, 0.5v = numpy.random.normal(mu,sigma,10000)# Plot a normalized histogram with 50 binspylab.hist(v, bins=50, normed=1)       # matplotlib version (plot)pylab.show()# Compute the histogram with numpy and then plot it(n, bins) = numpy.histogram(v, bins=50, normed=True)  # NumPy version (no plot)pylab.plot(.5*(bins[1:]+bins[:-1]), n)pylab.show()
0 0
原创粉丝点击