# No undershoot in hist

Hello,

thanks for the quick reply to my last problem.
Here I've got a new one:

While the last bin carries the overshoot, the first bin does not carry the
undershoot.

Example:

from numpy import *
from pylab import *

bins = 2 + arange(21)
data = arange(24)
print bins
print data
hist(data,bins)
show()

The last bin has two counts since it contains the entries 22 and 23 from data,
but the first bin has only one count, although it should carry the entries 0,1,2.

Is this intended?

Best regards,

Peter Melchior

Hi Peter,

this is also the behavior of the numpy histogram function. I personally don’t like it, but I think it’s kept for compatibility’s sake with Numeric. You could use

def histogram(a, bins):

``````n = sort(a).searchsorted(bins)
n = concatenate([n, [len(a)]])
count = concatenate([[n[0]], n[1:]-n[:-1]])
return count
``````

which will return an array where the first bin is the undershoot and the last the overshoot. If you need something fancier (or faster), you may want to look at the histogram function at http://www.scipy.org/DavidHuard (still a work in progress).

Cheers,
David

2007/3/15, Peter Melchior <
pmelchior@…1517…>:

···

Hello,

thanks for the quick reply to my last problem.
Here I’ve got a new one:

While the last bin carries the overshoot, the first bin does not carry the
undershoot.

Example:

from numpy import *

from pylab import *

bins = 2 + arange(21)
data = arange(24)
print bins
print data
hist(data,bins)
show()

The last bin has two counts since it contains the entries 22 and 23 from data,

but the first bin has only one count, although it should carry the entries 0,1,2.

Is this intended?

Best regards,

Peter Melchior

Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash

http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users