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

[Bug] histplot raises IndexError when plotting an histogram with one bin #431

Open
tcuisset opened this issue Jun 12, 2023 · 2 comments
Open

Comments

@tcuisset
Copy link

Hi,
histplot crashes when plotting histograms with a single bin, when trying to draw overflow bins.

Reproducer :

import hist
import mplhep as hep

h = hist.Hist(hist.axis.Regular(1, 0, 1))
h.fill([-1, 0.5])
hep.histplot(h)

Output

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[17], line 1
----> 1 hep.histplot(h)

File [***/lib/python3.10/site-packages/mplhep/plot.py:532], in histplot(H, bins, yerr, w2, w2method, stack, density, binwnorm, histtype, xerr, label, sort, edges, binticks, ax, flow, **kwargs)
    528 if underflow > 0.0:
    529     if flow == "hint":
    530         ax.plot(
    531             [
--> 532                 final_bins[0] - (final_bins[-3] - final_bins[2]) * 0.03,
    533                 final_bins[0],
    534             ],
    535             [0, 0],
    536             **kwargs,
    537         )
    538     if flow == "show":
    539         ax.plot(
    540             [flow_bins[1], flow_bins[2]],
    541             [0, 0],
    542             **kwargs,
    543         )

IndexError: index -3 is out of bounds for axis 0 with size 2
@andrzejnovak
Copy link
Member

Thanks for the report @tcuisset, @Ming-Yan could you take a look?

@Ming-Yan
Copy link
Contributor

Ming-Yan commented Jun 13, 2023

Hi @andrzejnovak @tcuisset ,thanks for pointing this out, I open a new PR to solve this issue for both 1d/2d hist

Ming-Yan added a commit to Ming-Yan/mplhep that referenced this issue Jun 14, 2023
andrzejnovak pushed a commit that referenced this issue Jul 10, 2023
* fix : flow plot bug on axis range for histplot and hist2dplot

* feat : add test for one bin hist with flow bins #431
jonas-eschle pushed a commit that referenced this issue Apr 22, 2024
* fix : flow plot bug on axis range for histplot and hist2dplot

* feat : add test for one bin hist with flow bins #431
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants