mesh_coloring.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. """Specify color mapping for cells
  2. and points of a Mesh"""
  3. from vedo import dataurl, Plotter, Mesh
  4. plt = Plotter(N=3, axes=11)
  5. ##################################### add a cell array
  6. man1 = Mesh(dataurl+"man_low.vtk").linewidth(0.1)
  7. nv = man1.ncells # nr. of cells
  8. scals = range(nv) # coloring by the index of cell
  9. man1.cmap("Paired", scals, on='cells').add_scalarbar("cell nr")
  10. plt.at(0).show(man1, __doc__, elevation=-60)
  11. ##################################### Point coloring
  12. man2 = Mesh(dataurl+"man_low.vtk")
  13. scals = man2.vertices[:, 0] + 37 # pick x coordinates of vertices
  14. man2.cmap("hot", scals)
  15. man2.add_scalarbar(horizontal=True)
  16. plt.at(1).show(man2, "mesh.cmap()")
  17. ##################################### Cell coloring
  18. man3 = Mesh(dataurl+"man_low.vtk")
  19. cell_centers = man3.cell_centers().coordinates
  20. scals = cell_centers[:, 2] + 37 # pick z coordinates of cells
  21. man3.cmap("afmhot", scals, on='cells')
  22. # Add a fancier 3D scalar bar embedded in the 3d scene
  23. man3.add_scalarbar3d(size=[0.2,3])
  24. man3.scalarbar.scale(1.1).rotate_x(90).shift([0,2,0])
  25. plt.at(2).show(man3, "mesh.cmap(on='cells')")
  26. plt.interactive()
  27. plt.close()