plot_density2d.py 811 B

12345678910111213141516171819202122232425
  1. """Density plot from a distribution of points in 2D"""
  2. import numpy as np
  3. from vedo import *
  4. settings.use_depth_peeling = True
  5. n = 10000
  6. p = np.random.normal(0, 0.3, (n,2))
  7. p[:int(n*1/3) ] += [1.0, 0.0] # shift 1/3 of the points along x by 1
  8. p[ int(n*2/3):] += [1.7, 0.4]
  9. # create the point cloud
  10. pts = Points(p).color('k', 0.2)
  11. # radius of local search can be specified (None=automatic)
  12. vol = pts.density(radius=None).cmap('Paired_r') # returns a Volume
  13. # Other cool color mapping: Set1_r, Dark2. Or you can build your own, e.g.:
  14. # vol.c(['w','w','y','y','r','r','g','g','b','k']).alpha([0,1])
  15. r = precision(vol.metadata['radius'], 2) # retrieve automatic radius value
  16. vol.add_scalarbar3d(title='Density (counts in r_search ='+r+')', c='k', italic=1)
  17. show([(pts,__doc__), vol], N=2, axes=True).close()