histo_1d_b.py 940 B

123456789101112131415161718192021222324252627282930313233343536
  1. """Superimpose and compare histograms"""
  2. import numpy as np
  3. from vedo.pyplot import histogram
  4. from vedo import settings
  5. settings.remember_last_figure_format = True
  6. np.random.seed(0)
  7. theory = np.random.randn(500).tolist()
  8. backgr = ((np.random.rand(100)-0.5)*6).tolist()
  9. data = np.random.randn(500).tolist() + backgr
  10. # A first histogram:
  11. fig = histogram(
  12. theory + backgr,
  13. ylim=(0,90),
  14. title=__doc__,
  15. xtitle='measured variable',
  16. c='red4',
  17. gap=0, # no gap between bins
  18. padding=0, # no extra spaces
  19. label="theory",
  20. )
  21. # Extract the 11th bin and color it purple
  22. fig[10].c('purple4')
  23. fig.add_label("special bin", marker='s', mc='purple4')
  24. # Add a second histogram to be superimposed
  25. fig += histogram(backgr, label='background')
  26. # Add the data histogram with poissonian errors
  27. fig += histogram(data, marker='o', errors=True, fill=False, label='data')
  28. fig.add_legend(s=0.8)
  29. fig.show(zoom='tight').close()