Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New slice function of Histdd to support binning fragment #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

zihaoxu98
Copy link

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,
Screenshot 2024-10-29 at 9 12 24 PM
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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant