File: plot_bars.py

package info (click to toggle)
vedo 2026.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,528 kB
  • sloc: python: 46,376; javascript: 1,900; xml: 437; sh: 110; makefile: 6
file content (30 lines) | stat: -rw-r--r-- 942 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""Use `plot(mode="bars")` for categorical counts."""
from vedo import precision, Text3D, color_map, settings
from vedo.pyplot import plot

settings.default_font = "Meson"

counts  = [1946, 8993, 3042, 1190, 1477,    0,    0]
percent = [11.68909178, 54.01850072, 18.27246516,  7.14800577,  8.87193657, 0, 0]
labels  = ['<100', '100-250', '250-500', '500-750', '750-1000', '1000-2000', '>2000']
colors  = color_map(range(len(counts)), "hot")

# plot() will return a PlotBars object
fig = plot(
    [counts, labels, colors],
    mode="bars",
    ylim=(0,10_000),
    aspect=16/9,
    title='Clusters in lux range',
    axes=dict(
        xlabel_rotation=30,
        xlabel_size=0.02,
    ),
)

for i in range(len(percent)):
    val = precision(percent[i], 3)+'%'
    txt = Text3D(val, pos=(fig.centers[i], counts[i]), justify="bottom-center").c("blue2")
    fig += txt.scale(200).shift(0,170,0)

fig.show(size=(1000,750), zoom='tight').close()