On Sun, 2007-04-08 at 19:25 +0200, David Fokkema wrote:
> On Fri, 2007-04-06 at 18:32 +0300, Jouni K. Seppänen wrote:
> > David Fokkema <[EMAIL PROTECTED]> writes:
> > 
> > > If I choose center, the result is that my histogram is calculated
> > > for edge values but the bars are placed at center values which is
> > > completely misleading and wrong! I'd say this is a bug, but I may be
> > > overlooking something here...
> > 
> > Looks like a bug to me. Could you file it at
> > http://sf.net/tracker/?group_id=80706&atid=560720
> > so it isn't forgotten?
> 
> Well... It couldn't be too hard to fix, I guess... I know python, I
> tracked down the source, I could try and fix it, right? I think I'll
> have the time next Tuesday, so hopefully I'll file a bug report with an
> attached patch, ;-)

I fixed the bug, I think. At least it's working on my system and I think
it is not invasive. Comments please? I'll send it upstream otherwise...

--- matplotlib/axes.py.orig     2007-04-10 10:58:30.000000000 +0200
+++ matplotlib/axes.py  2007-04-10 11:14:56.000000000 +0200
@@ -4149,7 +4149,7 @@
         hist bars
         """
         if not self._hold: self.cla()
-        n, bins = matplotlib.mlab.hist(x, bins, normed)
+        n, bins = matplotlib.mlab.hist(x, bins, normed, align)
         if width is None: width = 0.9*(bins[1]-bins[0])
         if orientation == 'horizontal':
             patches = self.barh(bins, n, height=width, left=bottom,
align=align)
--- matplotlib/mlab.py.orig     2007-04-10 11:16:23.000000000 +0200
+++ matplotlib/mlab.py  2007-04-10 11:24:48.000000000 +0200
@@ -597,7 +597,7 @@
    #S = -1.0*asum(p*log(p))
    return S
 
-def hist(y, bins=10, normed=0):
+def hist(y, bins=10, normed=0, align='edge'):
     """
     Return the histogram of y with bins equally sized bins.  If bins
     is an array, use the bins.  Return value is
@@ -626,11 +626,16 @@
         dy = (ymax-ymin)/bins 
         bins = ymin + dy*arange(bins)
 
+    if align == 'center':
+       hw = .5*(bins[1]-bins[0])
+       nbins = [x-hw for x in bins]
+    else:
+       nbins = bins
 
-    n = searchsorted(sort(y), bins)
+    n = searchsorted(sort(y), nbins)
     n = diff(concatenate([n, [len(y)]]))
     if normed:
-       db = bins[1]-bins[0]
+       db = nbins[1]-nbins[0]
        return 1/(len(y)*db)*n, bins
     else:
        return n, bins


Thanks,

David


-------------------------------------------------------------------------
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

Reply via email to