Skip to content

Commit bad5541

Browse files
committed
feat: new "band" histtype
1 parent f38157a commit bad5541

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/mplhep/plot.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def histplot(
152152
raise ValueError("ax must be a matplotlib Axes object")
153153

154154
# arg check
155-
_allowed_histtype = ["fill", "step", "errorbar"]
155+
_allowed_histtype = ["fill", "step", "errorbar", "band"]
156156
_err_message = f"Select 'histtype' from: {_allowed_histtype}"
157157
assert histtype in _allowed_histtype, _err_message
158158
assert flow is None or flow in {
@@ -462,6 +462,23 @@ def iterable_not_string(arg):
462462
return_artists.append(StairsArtists(_f, None, None))
463463
_artist = _f
464464

465+
elif histtype == "band":
466+
band_defaults = {
467+
"alpha": 0.5,
468+
"edgecolor": "lightgray",
469+
"hatch": "///",
470+
}
471+
for i in range(len(plottables)):
472+
_kwargs = _chunked_kwargs[i]
473+
_f = ax.stairs(
474+
**plottables[i].to_stairband(),
475+
label=_labels[i],
476+
fill=True,
477+
**soft_update_kwargs(_kwargs, band_defaults),
478+
)
479+
return_artists.append(StairsArtists(_f, None, None))
480+
_artist = _f
481+
465482
elif histtype == "errorbar":
466483
err_defaults = {
467484
"linestyle": "none",
@@ -480,14 +497,15 @@ def iterable_not_string(arg):
480497
_xerr = None
481498

482499
for i in range(len(plottables)):
500+
_kwargs = _chunked_kwargs[i]
483501
_plot_info = plottables[i].to_errorbar()
484502
if yerr is False:
485503
_plot_info["yerr"] = None
486504
_plot_info["xerr"] = _xerr
487505
_e = ax.errorbar(
488506
**_plot_info,
489507
label=_labels[i],
490-
**soft_update_kwargs(_chunked_kwargs[i], err_defaults),
508+
**soft_update_kwargs(_kwargs, err_defaults),
491509
)
492510
return_artists.append(ErrorBarArtists(_e))
493511

src/mplhep/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,14 @@ def density(self, boolean: bool):
265265
def to_stairs(self):
266266
return {"values": self.values, "edges": self.edges, "baseline": self.baseline}
267267

268+
def to_stairband(self):
269+
self.errors()
270+
return {
271+
"values": self.values + self.yerr_hi,
272+
"edges": self.edges,
273+
"baseline": self.values - self.yerr_lo,
274+
}
275+
268276
def to_errorbar(self):
269277
self.errors()
270278
return {

0 commit comments

Comments
 (0)