mesh_custom.py 790 B

1234567891011121314151617181920212223242526
  1. """Controlling the color and transparency
  2. of a Mesh with various color map definitions"""
  3. from vedo import Mesh, dataurl, printc, show
  4. import numpy as np
  5. man = Mesh(dataurl + "man.vtk")
  6. # let the scalar be the z coordinate of the mesh vertices
  7. scals = man.vertices[:, 2]
  8. # assign color map with specified opacities
  9. try:
  10. import colorcet
  11. # https://colorcet.holoviz.org
  12. mycmap = colorcet.bmy
  13. alphas = np.linspace(0.8, 0.2, num=len(mycmap))
  14. except ModuleNotFoundError:
  15. printc("colorcet is not available, use custom cmap", c='y')
  16. printc("pip install colorcet", c='y')
  17. mycmap = ["darkblue", "magenta", (1, 1, 0)]
  18. alphas = [0.8, 0.6, 0.2]
  19. man.cmap(mycmap, scals, alpha=alphas).add_scalarbar()
  20. show(man, __doc__, viewup="z", axes=7).close()