msfz751

normal_plot.dn.py

Oct 20th, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. # normal_plot.dn.py
  2. import nitroplot
  3. import numpy as np
  4.  
  5. mu, sigma = Cell("mu").value, Cell("sigma").value # mean and standard deviation
  6. s = np.random.normal(mu, sigma, Cell("samples").value)
  7.  
  8. n = [None] * 5000
  9. Cell("C3").vertical = n   # clear the vertical range
  10. Cell("C3").vertical = s   # fill the range with the samples
  11.  
  12. # Verify the mean and the variance:
  13.  
  14. error = Cell("error").value
  15.  
  16. abs(mu - np.mean(s)) < error
  17.  
  18. abs(sigma - np.std(s, ddof=1)) < error
  19.  
  20.  
  21. count, bins, ignored = nitroplot.hist(s, Cell("bins").value, normed=True)
  22.  
  23. nitroplot.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) * np.exp( - (bins - mu)**2 / (2 * sigma**2) ),linewidth=2, color='r')
  24. nitroplot.graph()
Advertisement
Add Comment
Please, Sign In to add comment