scalarbars.py 970 B

12345678910111213141516171819202122232425262728293031323334
  1. """Insert 2D and 3D scalarbars in the rendering scene"""
  2. from vedo import Mesh, dataurl, show
  3. shape = Mesh(dataurl + "lamp.vtk")
  4. ms = []
  5. cmaps = ("jet", "PuOr", "viridis")
  6. for i in range(3):
  7. s = shape.clone(deep=False).pos([0, i * 2.2, 0])
  8. # colorize mesh
  9. scalars = s.points[:, 2]
  10. s.cmap(cmaps[i], scalars)
  11. ms.append(s)
  12. # add 2D scalar bar to first mesh
  13. ms[0].add_scalarbar(title="my scalarbar\nnumber #0") # 2D
  14. # add 3D scalar bars
  15. ms[1].add_scalarbar3d(c="k", title="scalarbar #1", size=[0, 3])
  16. sc = ms[2].add_scalarbar3d(
  17. c="k",
  18. size=[None, 2.8], # change y-size only
  19. title="A viridis colormap\nscalarbar to play with",
  20. title_font="Quikhand",
  21. title_xoffset=-2, # offset of labels
  22. title_size=1.5,
  23. )
  24. sc.scalarbar.rotate_x(90).scale(1.2).shift(0,2,0) # make it vertical
  25. # create a 2D copy scalarbar to the 3D one
  26. sc2d = sc.scalarbar.clone2d(size=0.3, ontop=True)
  27. show(ms, sc2d, __doc__, axes=1, viewup="z").close()