numpy 画直方图

来源:互联网 发布:ear cuff淘宝 编辑:程序博客网 时间:2024/06/07 13:51

原文出处:点击打开链接      http://reverland.org/python/2012/08/22/numpy/


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 binsprint vprint type(v)pylab.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