plot_density3d.py 583 B

123456789101112131415161718192021
  1. """Density plot from a distribution of points in 3D"""
  2. import numpy as np
  3. from vedo import *
  4. settings.use_depth_peeling = True
  5. n = 3000
  6. p = np.random.normal(7, 0.3, (n,3))
  7. p[:int(n*1/3) ] += [1,0,0] # shift 1/3 of the points along x by 1
  8. p[ int(n*2/3):] += [1.7,0.4,0.2]
  9. pts = Points(p, alpha=0.5)
  10. vol = pts.density() # density() returns a Volume
  11. vol.cmap('Dark2').alpha([0.1,1])
  12. r = precision(vol.metadata['radius'][0], 2) # retrieve automatic radius value
  13. vol.add_scalarbar3d(title=f'Density (counts in r_s ={r})', italic=1)
  14. show(pts, vol, __doc__, axes=True).close()