histo_manual.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. """Categories and repeats"""
  2. # manually create a plot by adding Rectangles to a Figure object
  3. from vedo import np, settings, Rectangle, Text3D, Line, DashedLine
  4. from vedo.pyplot import Figure
  5. settings.default_font = "Theemim"
  6. #################################################################### First plot
  7. groupA = np.random.randn(3)*10+50
  8. groupB = np.random.randn(3)*10+60
  9. groupC = np.random.randn(3)*10+70
  10. fig = Figure(
  11. [-5,55], [-10,100], # x and y ranges
  12. xtitle='', ytitle='', # this disables x and y axes
  13. )
  14. #################
  15. x0 = 0
  16. for i in range(3):
  17. x1 = x0 + 4
  18. val= groupA[i]
  19. fig += Rectangle([x0,0], [x1, val], c=f'red{3+i*2}')
  20. x0 = x1
  21. fig += Text3D("Group A", justify='center', c='k').pos(6,-7).scale(4)
  22. fig += Line([-1,0], [13, 0], lw=2)
  23. #################
  24. x0 = 20
  25. for i in range(3):
  26. x1 = x0 + 4
  27. val= groupB[i]
  28. fig += Rectangle([x0,0], [x1, val], c=f'purple{3+i*2}')
  29. x0 = x1
  30. fig += Text3D("Group B", justify='center', c='k').pos(26,-7).scale(4)
  31. fig += Line([19,0], [33, 0], lw=2)
  32. #################
  33. x0 = 40
  34. for i in range(3):
  35. x1 = x0 + 4
  36. val= groupC[i]
  37. fig += Rectangle([x0,0], [x1, val], c=f'orange{3+i*2}')
  38. x0 = x1
  39. fig += Text3D("Group C", justify='center', c='k').pos(46,-7).scale(4)
  40. fig += Line([39,0], [53, 0], lw=2)
  41. #################
  42. fig += DashedLine([-2,50], [55,50], c='k3', lw=1)
  43. fig += Text3D("50%").pos(-7,49).scale(3).c('k')
  44. fig.show(size=(1000,700), zoom='tight', title=__doc__).clear()
  45. #################################################################### Second plot
  46. fig = Figure(
  47. [0, 100], [-20, 80],
  48. aspect=3/4, # can change the aspect ratio
  49. xtitle='', ytitle='', # this disables x and y axes
  50. )
  51. for i in range(5):
  52. val = np.random.randn()*10+50
  53. y0, y1 = 2*i, 2*i+1
  54. fig += Rectangle([0,y0], [100,y1], radius=0.5, c='k6')
  55. fig += Rectangle([0,y0], [val,y1], radius=0.5, c='r4').z(1)
  56. fig += Text3D("Group A", justify='center', c='k').pos(50,-5).scale(2.5)
  57. for i in range(5):
  58. val = np.random.randn()*10+60
  59. y0, y1 = 2*i + 20, 2*i+1 + 20
  60. fig += Rectangle([0,y0], [100,y1], radius=0.5, c='k6')
  61. fig += Rectangle([0,y0], [val,y1], radius=0.5, c='p5').z(1)
  62. fig += Text3D("Group B", justify='center', c='k').pos(50,15).scale(2.5)
  63. for i in range(5):
  64. val = np.random.randn()*10+70
  65. y0, y1 = 2*i + 40, 2*i+1 + 40
  66. fig += Rectangle([0,y0], [100,y1], radius=0.5, c='k6')
  67. fig += Rectangle([0,y0], [val,y1], radius=0.5, c='o5').z(1)
  68. fig += Text3D("Group C", justify='center', c='k').pos(50,35).scale(2.5)
  69. fig.show(size=(1000,700), zoom='tight').close()