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

[DOCS] How to plot histogram uncertainties with weighted fills? #587

Open
APN-Pucky opened this issue Sep 22, 2024 · 1 comment
Open

[DOCS] How to plot histogram uncertainties with weighted fills? #587

APN-Pucky opened this issue Sep 22, 2024 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@APN-Pucky
Copy link

APN-Pucky commented Sep 22, 2024

import numpy as np
import hist
hist1 = hist.Hist.new.Reg(50, 0, math.pi).Double()
hist1.fill(np.random.uniform(0, math.pi,200))
hist1.plot()

gives with (poisson) errorbars

2024-09-22_10-01-08_write

while

import numpy as np
import hist
hist1 = hist.Hist.new.Reg(50, 0, math.pi).Double()
hist1.fill(np.random.uniform(0, math.pi,200),weight=np.random.uniform(0, math.pi,200))
hist1.plot()

gives none

2024-09-22_10-01-13_write

I would have expected that it behaves like e.g. yoda that the weights squared produce the variance/uncertainty.

The docs https://hist.readthedocs.io/en/latest/reference/hist.plot.html#hist.plot.histplot say that I can give yerr, but yerr needs to be a vector of weights squared per bin. I don't think I should have to compute that myself, if I already filled the bins with the weights unsquared!
I could not find an example for this common case in the docs.
What is the recommended/right/best way to plot in hist with weights?


Note: on the webpage there seems to be a small formatting error:

Histogram object with containing values and optionally bins. Can be:

is followed by bulletpoints, while

Histogram uncertainties. Following modes are supported:

does show dashes without newlines per case.

@APN-Pucky APN-Pucky added the documentation Improvements or additions to documentation label Sep 22, 2024
@APN-Pucky
Copy link
Author

I guess I need to use .Weight() instead of .Double(), but that was not straightforward to find in the docs.

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

No branches or pull requests

1 participant