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

Add toggle for using the bin width as the x error for errorbar histograms #13

Merged
merged 2 commits into from
May 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion yahist/hist1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,7 @@ def plot(
legend=True,
counts=False,
errors=False,
errors_binwidth=True,
fmt="o",
label=None,
color=None,
Expand Down Expand Up @@ -1157,6 +1158,8 @@ def plot(
Font size of count labels
errors, bool False
If True, plot markers with error bars (`ax.errorbar()`) instead of `ax.hist()`.
errors_binwidth, bool True
If True, the bin width is plotted as the x error if `errors=True`.
fmt : str, default "o"
`fmt` kwarg used for matplotlib plotting
label : str, default None
Expand Down Expand Up @@ -1199,14 +1202,19 @@ def plot(
mask = ((counts != 0.0) | (yerrs != 0.0)) & np.isfinite(counts)
centers = self.bin_centers

if errors_binwidth:
xerr = xerrs[mask]
else:
xerr = None

if show_errors:
yerr = yerrs[mask]
if self.errors_up is not None:
yerr = self.errors_down[mask], self.errors_up[mask]
patches = ax.errorbar(
centers[mask],
counts[mask],
xerr=xerrs[mask],
xerr=xerr,
yerr=yerr,
fmt=fmt,
color=color,
Expand Down
Loading