histo_1d_c.py 903 B

1234567891011121314151617181920212223242526272829303132
  1. """Uniform distribution weighted by sin^2 12x + :onehalf"""
  2. import numpy as np
  3. from vedo import Line, settings
  4. from vedo.pyplot import histogram
  5. settings.default_font = "DejavuSansMono"
  6. data = np.random.rand(10000)
  7. weights = np.ones_like(data) * np.sin(12*data)**2 + 1/2
  8. fig = histogram(
  9. data,
  10. weights=weights,
  11. bins=50,
  12. aspect=16/9, # desired aspect ratio of the figure
  13. xtitle=__doc__, # x-axis title
  14. padding=[0,0,0,0.1], # allow 10% padding space only on the top
  15. gap=0, # no gap between bins
  16. ac='k7', # axes color
  17. c='yellow9',
  18. label='my histogram',
  19. )
  20. x = np.linspace(0,1, 200)
  21. y = 200*np.sin(12*x)**2 + 100
  22. fig += Line(np.c_[x, y], c='red5', lw=3).z(0.001)
  23. fig.add_label('my function', marker='-', mc='red5')
  24. fig.add_legend(pos=[0.7,1.33], alpha=0.2)
  25. fig.show(size=(1000,700), bg='black', zoom='tight').close()