mesh_lut.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. """Build a custom colormap, including
  2. out-of-range and NaN colors and labels"""
  3. from vedo import build_lut, Sphere, show
  4. # Generate a sphere and stretch it, so it sits between z=-2 and z=+2
  5. mesh = Sphere(quads=True).scale([1,1,1.8]).linewidth(1)
  6. # Create some dummy data array to be associated to points
  7. data = mesh.coordinates[:,2].copy() # pick z-coords, use them as scalar data
  8. data[10:70] = float('nan') # make some values invalid by setting to NaN
  9. data[300:600] = 100 # send some values very far above-scale
  10. # Build a custom Look-Up-Table of colors:
  11. # value, color, alpha
  12. lut = build_lut(
  13. [
  14. #(-2, 'pink' ), # up to -2 is pink
  15. (0.0, 'pink' ), # up to 0 is pink
  16. (0.4, 'green', 0.5), # up to 0.4 is green with alpha=0.5
  17. (0.7, 'darkblue' ),
  18. #( 2, 'darkblue' ),
  19. ],
  20. vmin=-1.2,
  21. vmax= 0.7,
  22. below_color='lightblue',
  23. above_color='grey',
  24. nan_color='red',
  25. interpolate=False,
  26. )
  27. # 3D scalarbar:
  28. mesh.cmap(lut, data).add_scalarbar3d(title='My Scalarbar', c='white')
  29. # mesh.scalarbar.scale(1.5).rotate_x(90).shift(0,2) # make it bigger and place it2)
  30. # OR 2D scalarbar:
  31. # mesh.cmap(lut, data).add_scalarbar()
  32. # OR 2D scalarbar derived from the 3D one:
  33. mesh.scalarbar = mesh.scalarbar.clone2d(pos=[0.7, -0.95], size=0.2)
  34. show(mesh,
  35. __doc__,
  36. axes=dict(zlabel_size=.04, number_of_divisions=10),
  37. elevation=-80,
  38. bg='blackboard',
  39. ).close()