histo_gauss.py 798 B

123456789101112131415161718192021222324252627282930
  1. """Superimpose histograms and curves"""
  2. import numpy as np
  3. from vedo.pyplot import histogram, plot
  4. from vedo import settings
  5. settings.default_font = "Bongas"
  6. settings.remember_last_figure_format = True
  7. mu, sigma, n, bins = 100.0, 15.0, 600, 50
  8. samples = np.random.normal(loc=mu, scale=sigma, size=n)
  9. x = np.linspace(min(samples), max(samples), num=50)
  10. y = 1/(sigma*np.sqrt(2*np.pi)) * np.exp( -(x-mu)**2 /(2*sigma**2))
  11. dy = 1/np.sqrt(n)
  12. fig = histogram(
  13. samples,
  14. title=__doc__,
  15. bins=bins,
  16. density=True,
  17. c='cyan3',
  18. aspect=9/7,
  19. label="gaussian",
  20. )
  21. fig += plot(x, y, "-", lc='orange5', label="some fit")
  22. fig += plot(x, y*(1+dy), "--", c='orange5', lw=2)
  23. fig += plot(x, y*(1-dy), "--", c='orange5', lw=2)
  24. fig.add_legend()
  25. fig.show(size=(800,700), zoom="tight").close()