Based on boost-histogram’s Transform, hist provides a powerful transform system on Regular axes that allows you to provide a functional form for the conversion between a regular spacing and the actual bin edges. The following transforms are built in:

  • hist.axis.transform.sqrt: A square root transform;

  • hist.axis.transform.log: A logarithmic transform;

  • hist.axis.transform.Pow(power): Raise to a specified power;

  • hist.axis.transform.Function: Specify arbitrary conversion functions.

Transform Types#

Here we show some basic usage of transforms in histogramming with pure Python. For more customized usage, you can refer the part in that of boost-histogram.

import ctypes
import math

import numpy as np

import hist
from hist import Hist
axis0 = hist.axis.Regular(10, 1, 4, name="A", transform=hist.axis.transform.sqrt)
axis1 = hist.axis.Regular(10, 1, 4, name="B", transform=hist.axis.transform.log)
axis2 = hist.axis.Regular(10, 1, 4, name="C", transform=hist.axis.transform.Pow(2))

ftype = ctypes.CFUNCTYPE(ctypes.c_double, ctypes.c_double)
axis3 = hist.axis.Regular(
    transform=hist.axis.transform.Function(ftype(math.log), ftype(math.exp)),
axis4 = hist.axis.Regular(
    transform=hist.axis.transform.Function(ftype(np.log), ftype(np.exp)),
h = Hist(axis0, axis1, axis2, axis3, axis4)

Histogram’s Transforms#

Hist also provides transform shortcuts for histograms. hist’s keeps the features of boost-histogram, and you can pass transform as a keyword argument when creating an axis. hist also allows you to use the .new shortcut directly when creating a Histogram for common transforms:

h0 =, 1, 4).Sqrt(10, 4, 9).Double()
h1 =, 1, 4).Log(10, 4, 9).Double()
h2 =, 1, 4, power=3).Pow(10, 1, 4, power=5).Double()

h3 = (, 1, 4, forward=ftype(math.log), inverse=ftype(math.exp))
    .Func(10, 1, 4, forward=ftype(np.log), inverse=ftype(np.exp))