Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: array copy and logic
Browse files Browse the repository at this point in the history
jonas-eschle committed Apr 1, 2024
1 parent f3ad6af commit f9c63b2
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions src/mplhep/plot.py
Original file line number Diff line number Diff line change
@@ -188,36 +188,33 @@ def histplot(
plottables = []
flow_bins = final_bins
for i, h in enumerate(hists):
value, variance = h.values().copy(), h.variances()
value, variance = np.copy(h.values()), h.variances()
if variance is not None:
variance = variance.copy()
variance = np.copy(variance)
underflow, overflow = 0, 0
underflowv, overflowv = 0, 0
# One sided flow bins - hist
if hasattr(h, "axes") and hasattr(h.axes[0], "traits"):
if hasattr(h.axes[0].traits, "overflow") and h.axes[0].traits.overflow:
overflow = h.values(flow=True)[-1].copy()
overflowv = h.variances(flow=True)[-1].copy()
overflow = np.copy(h.values(flow=True)[-1])
overflowv = np.copy(h.variances(flow=True)[-1])
if hasattr(h.axes[0].traits, "underflow") and h.axes[0].traits.underflow:
underflow = h.values(flow=True)[0].copy()
underflowv = h.variances(flow=True)[0].copy()
underflow = np.copy(h.values(flow=True)[0])
underflowv = np.copy(h.variances(flow=True)[0])
# Both flow bins exist - uproot
if hasattr(h, "values") and "flow" in inspect.getfullargspec(h.values).args:
elif hasattr(h, "values") and "flow" in inspect.getfullargspec(h.values).args:
if len(h.values()) + 2 == len(
h.values(flow=True)
): # easy case, both over/under
underflow, overflow = (
h.values(flow=True)[0].copy(),
h.values(flow=True)[-1].copy(),
np.copy(h.values(flow=True)[0]),
np.copy(h.values(flow=True)[-1]),
)
underflowv, overflowv = (
h.variances(flow=True)[0].copy(),
h.variances(flow=True)[-1].copy(),
np.copy(h.variances(flow=True)[0]),
np.copy(h.variances(flow=True)[-1]),
)
# Bins cannot be parsed
else:
underflow, overflow = 0, 0
underflowv, overflowv = 0, 0


# Set plottables
if flow == "none":
@@ -228,7 +225,7 @@ def histplot(
_flow_bin_size = np.max(
[0.05 * (final_bins[-1] - final_bins[0]), np.mean(np.diff(final_bins))]
)
flow_bins = final_bins.copy()
flow_bins = np.copy(final_bins)
if underflow > 0:
flow_bins = np.r_[flow_bins[0] - _flow_bin_size, flow_bins]
value = np.r_[underflow, value]
@@ -675,7 +672,7 @@ def hist2dplot(

# TODO: use Histogram everywhere

H = h.values().copy()
H = np.copy(h.values())
xbins, xtick_labels = get_plottable_protocol_bins(h.axes[0])
ybins, ytick_labels = get_plottable_protocol_bins(h.axes[1])
# Show under/overflow bins
@@ -715,7 +712,7 @@ def hist2dplot(
H = padded
xbins, ybins = pxbins, pybins
elif flow == "sum":
H = h.values().copy()
H = np.copy(h.values())
# Sum borders
H[0], H[-1] = (
H[0] + h.values(flow=True)[0, 1:-1],

0 comments on commit f9c63b2

Please sign in to comment.