Hist Quick Demo

My favorite demo notebook config setting:

[1]:
%config InteractiveShell.ast_node_interactivity="last_expr_or_assign"

Let’s import Hist:

[2]:
from hist import Hist
import numpy as np

We can use the classic constructors from boost-histogram, but let’s use the new QuickConstruct system instead:

[3]:
h = Hist.new.Reg(100, -10, 10, name="x").Double()
[3]:
-10 10 x
Regular(100, -10, 10, name='x', label='x')

Double() Σ=0.0

Let’s fill it with some data:

[4]:
h.fill(np.random.normal(1, 3, 1_000_000))
[4]:
-10 10 x
Regular(100, -10, 10, name='x', label='x')

Double() Σ=998559.0 (1000000.0 with flow)

And you can keep filling:

[5]:
h.fill(np.random.normal(-3, 1, 100_000))
[5]:
-10 10 x
Regular(100, -10, 10, name='x', label='x')

Double() Σ=1098559.0 (1100000.0 with flow)

You can plot (uses mplhep in the backend):

[6]:
h.plot();
../_images/examples_HistDemo_12_0.png

We also have direct access to histoprint:

[7]:
h.show(columns=50)
-1.00e+01 _                             2.67e+04 ╷
-9.80e+00 _
-9.60e+00 _
-9.40e+00 _
-9.20e+00 _
-9.00e+00 _
-8.80e+00 _
-8.60e+00 _
-8.40e+00 _
-8.20e+00 _
-8.00e+00 _
-7.80e+00 _
-7.60e+00 _
-7.40e+00 _
-7.20e+00 _
-7.00e+00 _
-6.80e+00 _
-6.60e+00 _
-6.40e+00 _
-6.20e+00 _
-6.00e+00 _
-5.80e+00 _
-5.60e+00 _
-5.40e+00 _
-5.20e+00 _
-5.00e+00 _
-4.80e+00 _
-4.60e+00 _
-4.40e+00 _
-4.20e+00 _
-4.00e+00 _
-3.80e+00 _
-3.60e+00 _
-3.40e+00 _
-3.20e+00 _
-3.00e+00 _
-2.80e+00 _
-2.60e+00 _
-2.40e+00 _
-2.20e+00 _
-2.00e+00 _
-1.80e+00 _
-1.60e+00 _
-1.40e+00 _
-1.20e+00 _
-1.00e+00 _
-8.00e-01 _
-6.00e-01 _
-4.00e-01 _
-2.00e-01 _
 0.00e+00 _
 2.00e-01 _
 4.00e-01 _
 6.00e-01 _
 8.00e-01 _
 1.00e+00 _
 1.20e+00 _
 1.40e+00 _
 1.60e+00 _
 1.80e+00 _
 2.00e+00 _
 2.20e+00 _
 2.40e+00 _
 2.60e+00 _
 2.80e+00 _
 3.00e+00 _
 3.20e+00 _
 3.40e+00 _
 3.60e+00 _
 3.80e+00 _
 4.00e+00 _
 4.20e+00 _
 4.40e+00 _
 4.60e+00 _
 4.80e+00 _
 5.00e+00 _
 5.20e+00 _
 5.40e+00 _
 5.60e+00 _
 5.80e+00 _
 6.00e+00 _
 6.20e+00 _
 6.40e+00 _
 6.60e+00 _
 6.80e+00 _
 7.00e+00 _
 7.20e+00 _
 7.40e+00 _
 7.60e+00 _
 7.80e+00 _
 8.00e+00 _
 8.20e+00 _
 8.40e+00 _
 8.60e+00 _
 8.80e+00 _
 9.00e+00 _
 9.20e+00 _
 9.40e+00 _
 9.60e+00 _
 9.80e+00 _
 1.00e+01 _

Let’s try 2D:

[8]:
h2 = Hist.new.Reg(100, -10, 10, name="x").Reg(100, -10, 10, name="y").Double()
[8]:
-10 10 -10 10 x y