from pyhs3.data import BinnedData, GaussianUncertainty
from pyhs3.axes import BinnedAxis

# Create binned data with uncertainties
contents = [12.5, 18.3, 15.7, 22.1, 19.4]
sigma = [3.5, 4.3, 4.0, 4.7, 4.4]

data = BinnedData(
    name="with_errors",
    type="binned",
    contents=contents,
    axes=[BinnedAxis(name="mass", min=100.0, max=150.0, nbins=5)],
    uncertainty=GaussianUncertainty(type="gaussian_uncertainty", sigma=sigma)
)

# Convert to hist and plot with error bars
h = data.to_hist()
h.plot(yerr=True, histtype="errorbar", marker="o", label="Data")
plt.xlabel("Mass [GeV]")
plt.ylabel("Events")
plt.legend()
plt.title("Histogram with Uncertainties")