File: histo_1d_d.py

package info (click to toggle)
vedo 2025.5.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,404 kB
  • sloc: python: 64,792; javascript: 1,932; xml: 437; sh: 139; makefile: 6
file content (43 lines) | stat: -rw-r--r-- 1,120 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
31
32
33
34
35
36
37
38
39
40
41
42
43
"""Insert a Figure into another (note that the x-axes stay aligned)"""
from vedo import Marker, settings, show, np
from vedo.pyplot import histogram

settings.default_font = "Ubuntu"

data = np.random.normal(loc=100, size=1000) + 7

################## Create the first Figure
fig1 = histogram(
    data,
    bins=20,
    xlim=(95,111),
    aspect=16/9,
    xtitle="shifted gaussian",
    c='cyan3',
)
# let's add an asterix marker where the mean is
fig1 += Marker('a', [fig1.mean,150,0.1], s=8).c('orange5')

################## Create a second Figure
fig2 = histogram(
    data - 7,
    bins=60,
    aspect=4/3,
    density=True,
    outline=True,
    c='purple9',
    axes=dict(xygrid=True, xyplane_color='grey2', xyalpha=1, grid_linewidth=0),
    label='finer binning',
)
# let's add an asterix marker where the mean is
fig2 += Marker('a', [fig2.mean,0.2,0.1], s=0.02).c('orange5')

# shift fig2 in vertical by 25, and in z by 0.1 (to make it show on top)
fig2.shift(0, 25, 0.1)

################## Insert fig2 into fig1
fig2.add_legend()
fig1.insert(fig2)

show(fig1, __doc__, zoom='tight', size=(1200,900)).close()