ANEW -histogram_demo NEEDS -gaussj NEEDS -gnuplot DOC (* #!/usr/bin/env python import numpy as np import matplotlib.mlab as mlab import matplotlib.pyplot as plt mu, sigma = 100, 15 x = mu + sigma*np.random.randn(10000) # the histogram of the data n, bins, patches = plt.hist(x, 50, normed=1, facecolor='green', alpha=0.75) # add a 'best fit' line y = mlab.normpdf( bins, mu, sigma) l = plt.plot(bins, y, 'r--', linewidth=1) 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() *) ENDDOC #10000 DOUBLE ARRAY x{ 100e FCONSTANT mu 15e FCONSTANT sigma -- 1 (x-mu)^2 -- ------------------ exp - --------- -- sqrt(2*pi*sigma^2) 2 sigma^2 : NORM-PDF ( F: x -- y ) PI*2 sigma FSQR F* FSQRT 1/F FSWAP mu F- FSQR FNEGATE sigma FSQR F2* F/ FEXP F* ; : histogram_demo ( -- ) 0 FIGURE CLF TRUE GRID S" Histogram of IQ: %\mu%=100, %\sigma%=15" TITLE S" Smarts" XLABEL S" Probability" YLABEL 40e 160e 0e 0.03e AXIS! x{ mu sigma NORMRND [PHOLD x{ #100 HIST S" #green" PLOT 40e 160e S" red" ['] NORM-PDF #100 FPLOT PHOLD] ;