8000 [Bug] histplot raises IndexError when plotting an histogram with one bin · Issue #431 · scikit-hep/mplhep · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
[Bug] histplot raises IndexError when plotting an histogram with one bin #431
@tcuisset

Description

@tcuisset

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0