histo_2d_a.py 619 B

123456789101112131415161718192021222324
  1. """Histogram of 2 variables"""
  2. from vedo import Marker, Points, np
  3. from vedo.pyplot import histogram
  4. n = 10_000
  5. x = np.random.randn(n) + 20
  6. y = x + np.random.randn(n) + 10
  7. xm, ym = np.mean(x), np.mean(y)
  8. histo = histogram(
  9. x, y, # this is interpreted as 2D
  10. bins=25,
  11. zlim=(0,150), # saturate color above 150 entries
  12. cmap='Blues_r',
  13. ztitle="Number of entries in bin",
  14. )
  15. # Add a marker to the plot
  16. histo += Marker('*', s=0.2, c='r').pos(xm, ym, 0.2)
  17. # Add also the original points
  18. pts = np.array([x,y]).T
  19. histo += Points(pts, r=2).z(0.1)
  20. histo.show(zoom='tight', bg='light yellow').close()