from pyhs3.distributions.histfactory.samples import Sample
from pyhs3.axes import Axes

# Create a HistFactory sample
sample = Sample(
    name="signal",
    data={
        "contents": [10.0, 20.0, 15.0, 25.0],
        "errors": [3.0, 4.0, 3.5, 4.5]
    }
)

# Provide axes for binning
axes = Axes([{"name": "mass", "min": 100.0, "max": 140.0, "nbins": 4}])

# Convert to hist
h = sample.to_hist(axes)
h.plot(yerr=True, histtype="errorbar", marker="s", label=sample.name)
plt.xlabel("mass [GeV]")
plt.ylabel("Events")
plt.legend()
plt.title("HistFactory Sample")