Issue
pyplot.hist()
documentation specifies that when setting a range for a histogram "lower and upper outliers are ignored".
Is it possible to make the first and last bins of a histogram include all outliers without changing the width of the bin?
For example, let's say I want to look at the range 0-3
with 3 bins: 0-1, 1-2, 2-3
(let's ignore cases of exact equality for simplicity). I would like the first bin to include all values from minus infinity to 1, and the last bin to include all values from 2 to infinity. However, if I explicitly set these bins to span that range, they will be very wide. I would like them to have the same width. The behavior I am looking for is like the behavior of hist()
in Matlab.
Obviously I can numpy.clip()
the data and plot that, which will give me what I want. But I am interested if there is a builtin solution for this.
Solution
No. Looking at matplotlib.axes.Axes.hist
and the direct use of numpy.histogram
I'm fairly confident in saying that there is no smarter solution than using clip (other than extending the bins that you histogram with).
I'd encourage you to look at the source of matplotlib.axes.Axes.hist
(it's just Python code, though admittedly hist is slightly more complex than most of the Axes methods) - it is the best way to verify this kind of question.
Answered By - pelson
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.