multihist
multihist copied to clipboard
New slice function of Histdd to support binning fragment
This PR modifies the function Histdd.slice
, to let it support binning fragment when the start
or stop
are not exactly at the bin edges. The fragments are calculated by multiplying the original histogram by the bin volume inclusion fraction.
For example,
is from the the following code
from multihist import Histdd
import numpy as np
import matplotlib.pyplot as plt
sample_size = int(1e6)
x = np.random.uniform(0, 1, sample_size)
r = np.sqrt(np.random.uniform(0, 100, sample_size))
hist = Histdd(x, r, bins=[np.linspace(0, 1, 30), np.linspace(0, 10, 11)], axis_names=['x', 'r'])
hist.project(axis=1).plot(label='Full hisotgram')
hist.slice(3.2, 7.6, axis=1).project(axis='r').plot(label='Sliced histogram from 3.2 to 7.6')
hist.slice(-2, -0.5, axis=1).project(axis='r').plot(label='Sliced histogram from -2 to -0.5')
hist.slice(8.4, 12, axis=1).project(axis='r').plot(label='Sliced histogram from 8.4 to 12')
plt.legend()
plt.show()