plot_bars.py 946 B

123456789101112131415161718192021222324252627282930
  1. # A plot(mode="bars") example. Useful to plot categories.
  2. from vedo import precision, Text3D, color_map, settings
  3. from vedo.pyplot import plot
  4. settings.default_font = "Meson"
  5. counts = [1946, 8993, 3042, 1190, 1477, 0, 0]
  6. percent = [11.68909178, 54.01850072, 18.27246516, 7.14800577, 8.87193657, 0, 0]
  7. labels = ['<100', '100-250', '250-500', '500-750', '750-1000', '1000-2000', '>2000']
  8. colors = color_map(range(len(counts)), "hot")
  9. # plot() will return a PlotBars object
  10. fig = plot(
  11. [counts, labels, colors],
  12. mode="bars",
  13. ylim=(0,10_000),
  14. aspect=16/9,
  15. title='Clusters in lux range',
  16. axes=dict(
  17. xlabel_rotation=30,
  18. xlabel_size=0.02,
  19. ),
  20. )
  21. for i in range(len(percent)):
  22. val = precision(percent[i], 3)+'%'
  23. txt = Text3D(val, pos=(fig.centers[i], counts[i]), justify="bottom-center").c("blue2")
  24. fig += txt.scale(200).shift(0,170,0)
  25. fig.show(size=(1000,750), zoom='tight').close()