Skip to content

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

@APN-Pucky

Description

@APN-Pucky
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions