File: histo_2d_a.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 (24 lines) | stat: -rw-r--r-- 619 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
"""Histogram of 2 variables"""
from vedo import Marker, Points, np
from vedo.pyplot import histogram

n = 10_000
x = np.random.randn(n) + 20
y = x + np.random.randn(n) + 10
xm, ym = np.mean(x), np.mean(y)

histo = histogram(
    x, y,         # this is interpreted as 2D
    bins=25,
    zlim=(0,150), # saturate color above 150 entries
    cmap='Blues_r',
    ztitle="Number of entries in bin",
)
# Add a marker to the plot
histo += Marker('*', s=0.2, c='r').pos(xm, ym, 0.2)

# Add also the original points
pts = np.array([x,y]).T
histo += Points(pts, r=2).z(0.1)

histo.show(zoom='tight', bg='light yellow').close()