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() Σ=998506.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() Σ=1098506.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.000 _ x 10^+01                     26783/row ╷
 -0.980 _
 -0.960 _
 -0.940 _
 -0.920 _
 -0.900 _
 -0.880 _
 -0.860 _
 -0.840 _
 -0.820 _
 -0.800 _
 -0.780 _
 -0.760 _
 -0.740 _
 -0.720 _
 -0.700 _
 -0.680 _
 -0.660 _
 -0.640 _
 -0.620 _
 -0.600 _
 -0.580 _
 -0.560 _
 -0.540 _
 -0.520 _
 -0.500 _
 -0.480 _
 -0.460 _
 -0.440 _
 -0.420 _
 -0.400 _
 -0.380 _
 -0.360 _
 -0.340 _
 -0.320 _
 -0.300 _
 -0.280 _
 -0.260 _
 -0.240 _
 -0.220 _
 -0.200 _
 -0.180 _
 -0.160 _
 -0.140 _
 -0.120 _
 -0.100 _
 -0.080 _
 -0.060 _
 -0.040 _
 -0.020 _
  0.000 _
  0.020 _
  0.040 _
  0.060 _
  0.080 _
  0.100 _
  0.120 _
  0.140 _
  0.160 _
  0.180 _
  0.200 _
  0.220 _
  0.240 _
  0.260 _
  0.280 _
  0.300 _
  0.320 _
  0.340 _
  0.360 _
  0.380 _
  0.400 _
  0.420 _
  0.440 _
  0.460 _
  0.480 _
  0.500 _
  0.520 _
  0.540 _
  0.560 _
  0.580 _
  0.600 _
  0.620 _
  0.640 _
  0.660 _
  0.680 _
  0.700 _
  0.720 _
  0.740 _
  0.760 _
  0.780 _
  0.800 _
  0.820 _
  0.840 _
  0.860 _
  0.880 _
  0.900 _
  0.920 _
  0.940 _
  0.960 _
  0.980 _
  1.000 _

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