X Tutup
Skip to content

Bug with plt.hist when min==max and values are >= 2**53 #8091

@astrofrog

Description

@astrofrog

The following call to plt.hist fails:

In [33]: plt.hist([2**53])
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-33-d271f9359197> in <module>()
----> 1 plt.hist([2**53])

/Users/tom/miniconda3/envs/dev/lib/python3.6/site-packages/matplotlib/pyplot.py in hist(x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, hold, data, **kwargs)
   3080                       histtype=histtype, align=align, orientation=orientation,
   3081                       rwidth=rwidth, log=log, color=color, label=label,
-> 3082                       stacked=stacked, data=data, **kwargs)
   3083     finally:
   3084         ax._hold = washold

/Users/tom/miniconda3/envs/dev/lib/python3.6/site-packages/matplotlib/__init__.py in inner(ax, *args, **kwargs)
   1890                     warnings.warn(msg % (label_namer, func.__name__),
   1891                                   RuntimeWarning, stacklevel=2)
-> 1892             return func(ax, *args, **kwargs)
   1893         pre_doc = inner.__doc__
   1894         if pre_doc is None:

/Users/tom/miniconda3/envs/dev/lib/python3.6/site-packages/matplotlib/axes/_axes.py in hist(self, x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, **kwargs)
   6190             # this will automatically overwrite bins,
   6191             # so that each histogram uses the same bins
-> 6192             m, bins = np.histogram(x[i], bins, weights=w[i], **hist_kwargs)
   6193             m = m.astype(float)  # causes problems later if it's an int
   6194             if mlast is None:

/Users/tom/miniconda3/envs/dev/lib/python3.6/site-packages/numpy/lib/function_base.py in histogram(a, bins, range, normed, weights, density)
    598             # The index computation is not guaranteed to give exactly
    599             # consistent results within ~1 ULP of the bin edges.
--> 600             decrement = tmp_a_data < bin_edges[indices]
    601             indices[decrement] -= 1
    602             # The last bin includes the right edge. The other bins do not.

IndexError: index -9223372036854775808 is out of bounds for axis 1 with size 11
<matplotlib.figure.Figure at 0x134861278>

fails, whereas:

In [34]: plt.hist([2**53-1])
Out[34]: 
(array([ 0.,  0.,  0.,  0.,  0.,  0.,  1.,  0.,  0.,  0.]),
 array([  9.00719925e+15,   9.00719925e+15,   9.00719925e+15,
          9.00719925e+15,   9.00719925e+15,   9.00719925e+15,
          9.00719925e+15,   9.00719925e+15,   9.00719925e+15,
          9.00719925e+15,   9.00719925e+15]),
 <a list of 10 Patch objects>)
<matplotlib.figure.Figure at 0x135106860>

succeeds. This is to do with the face min==max because the following succeeds:

In [41]: plt.hist([2**53, 2**54])
Out[41]: 
(array([ 1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  1.]),
 array([  9.00719925e+15,   9.90791918e+15,   1.08086391e+16,
          1.17093590e+16,   1.26100790e+16,   1.35107989e+16,
          1.44115188e+16,   1.53122387e+16,   1.62129587e+16,
          1.71136786e+16,   1.80143985e+16]),
 <a list of 10 Patch objects>)
<matplotlib.figure.Figure at 0x1359efda0>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup