glyphs2.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. """Draw color arrow glyphs"""
  2. from vedo import Sphere, Arrows, get_color, show
  3. import numpy as np
  4. # Create two spheres with different radii, wireframes,
  5. # and colors, and set the position of one of them
  6. s1 = Sphere(r=10, res=8).wireframe().c('white')
  7. s2 = Sphere(r=20, res=8).wireframe().c('white',0.1).pos(0,4,0)
  8. # Get the coordinates of the coordinates of each sphere
  9. coords1 = s1.coordinates
  10. coords2 = s2.coordinates
  11. # --- color can be a colormap which maps arrow sizes
  12. # Define a title for the first set of arrows,
  13. # and create an Arrows object with coordinates and a colormap for color
  14. t1 = 'Color arrows by size\nusing a color map'
  15. a1 = Arrows(coords1, coords2, c='coolwarm', alpha=0.4)
  16. a1.add_scalarbar(c='w')
  17. # --- get a list of random rgb colors
  18. # Generate a list of random RGB colors for each arrow
  19. # based on an array of integers, and define a title for the second set of arrows
  20. nrs = np.random.randint(0, 10, len(coords1))
  21. cols = get_color(nrs)
  22. t2 = 'Color arrows by an array\nand scale them by half'
  23. a2 = Arrows(coords1, coords2, c=cols)
  24. # Display two groups of objects on two renderers: the two spheres,
  25. # the Arrows object with a colormap for color and a scalar bar,
  26. # and the title for the first set of arrows on one renderer;
  27. # the two spheres, the Arrows object with random RGB colors,
  28. # and the title for the second set of arrows on another renderer
  29. show([(s1, s2, a1, t1), (s1, s2, a2, t2)], N=2, bg='bb', bg2='lb').close()