Re: [Matplotlib-users] Histogram align 'edge' or 'center' bug?

2007-04-10 Thread David Fokkema
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=80706atid=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.0 +0200
+++ matplotlib/axes.py  2007-04-10 11:14:56.0 +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.0 +0200
+++ matplotlib/mlab.py  2007-04-10 11:24:48.0 +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.phpp=sourceforgeCID=DEVDEV
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Histogram align 'edge' or 'center' bug?

2007-04-10 Thread Jouni K . Seppänen
David Fokkema [EMAIL PROTECTED] writes:

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

Does this handle the case where the user has specified bins of
different widths? It looks like you are only using the width of the
first bin:

 +if align == 'center':
 +   hw = .5*(bins[1]-bins[0])
 +   nbins = [x-hw for x in bins]
 +else:
 +   nbins = bins

At least, I've always thought that unequal bins are allowed, but from
the following it seems that the probability density support also makes
an incompatible assumption:

  if normed:
 -   db = bins[1]-bins[0]
 +   db = nbins[1]-nbins[0]
 return 1/(len(y)*db)*n, bins

-- 
Jouni K. Seppänen
http://www.iki.fi/jks


-
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.phpp=sourceforgeCID=DEVDEV
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Histogram align 'edge' or 'center' bug?

2007-04-10 Thread David Fokkema
On Tue, 2007-04-10 at 16:13 +0300, Jouni K. Seppänen wrote:
 David Fokkema [EMAIL PROTECTED] writes:
 
  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...
 
 Does this handle the case where the user has specified bins of
 different widths? It looks like you are only using the width of the
 first bin:
 
  +if align == 'center':
  +   hw = .5*(bins[1]-bins[0])
  +   nbins = [x-hw for x in bins]
  +else:
  +   nbins = bins

I am only using the first width, indeed. If different widths are allowed
(and why not?) some more coding has to be done. On the other hand, I use
align = 'center' because I have a detector which samples timing
information at 20 ns intervals. So, when binning timing information, I
only have 0, 20 ns, 40 ns, 60 ns and so forth. Being able to specify
those values as the center of my bin instead of calculating edges myself
(-10, 10, 30, 50, etc.) is very useful. I can't think of an application
where you have bins of different widths and you want to center the
values... Furthermore, when plotting the histogram, the function
calculates the width of the bars only for the first bin and uses that
for all bars. So I think this function is highly unstable when you use
variable sized bins. Matplotlib.mlab.hist only calculates the histogram
and can only use variable sized bins when you want a simple histogram.
Maybe add something to this effect in the docstring?

 
 At least, I've always thought that unequal bins are allowed, but from
 the following it seems that the probability density support also makes
 an incompatible assumption:
 
   if normed:
  -   db = bins[1]-bins[0]
  +   db = nbins[1]-nbins[0]
  return 1/(len(y)*db)*n, bins
 

It does...

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.phpp=sourceforgeCID=DEVDEV
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Histogram align 'edge' or 'center' bug?

2007-04-10 Thread Jouni K . Seppänen
David Fokkema [EMAIL PROTECTED] writes:

 I can't think of an application where you have bins of different
 widths and you want to center the values...

Actually, now that I think about it, there is not enough information
in the bin centers to know the widths of the bins if they may vary.
For example, if your bin edges are (2, 4, 8, 16, 32) or (1, 5, 7, 17,
31), you get the same bin centers (3, 6, 12, 24). Perhaps it's best to
disallow variable-width bins when align='center'.

-- 
Jouni K. Seppänen
http://www.iki.fi/jks


-
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.phpp=sourceforgeCID=DEVDEV
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Histogram align 'edge' or 'center' bug?

2007-04-08 Thread David Fokkema
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=80706atid=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, ;-)


-
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.phpp=sourceforgeCID=DEVDEV
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Histogram align 'edge' or 'center' bug?

2007-04-06 Thread Jouni K . Seppänen
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=80706atid=560720
so it isn't forgotten?

-- 
Jouni K. Seppänen
http://www.iki.fi/jks


-
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.phpp=sourceforgeCID=DEVDEV
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Histogram align 'edge' or 'center' bug?

2007-04-04 Thread David Fokkema
Hi group,

I have the following ipython 'session':

In [23]: data = [0, 0.4, 0.6, 1, 2, 3]

In [24]: bins = [0, 1, 2, 3]

In [25]: hist(data, bins, align='edge')
Out[25]: (array([3, 1, 1, 1]), [0, 1, 2, 3], a list of 4 Patch
objects)

In [26]: hist(data, bins, align='center')
Out[26]: (array([3, 1, 1, 1]), [0, 1, 2, 3], a list of 4 Patch
objects)


I would suspect that the histogram output from 'center' should be [2, 2,
1, 1]. Why is this not so? At least, the two should be different? I
would say that with edge, my bins would be 0-1, 1-2, 2-3, 3-4, and that
center should give me -0.5-0.5, 0.5-1.5, 1.5-2.5, 2.5-3.5, but this
seems not to be the case??? Any help understanding this would be greatly
appreciated!

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.phpp=sourceforgeCID=DEVDEV
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Histogram align 'edge' or 'center' bug?

2007-04-04 Thread David Fokkema
On Wed, 2007-04-04 at 16:26 +0200, David Fokkema wrote:
 Hi group,
 
 I have the following ipython 'session':
 
 In [23]: data = [0, 0.4, 0.6, 1, 2, 3]
 
 In [24]: bins = [0, 1, 2, 3]
 
 In [25]: hist(data, bins, align='edge')
 Out[25]: (array([3, 1, 1, 1]), [0, 1, 2, 3], a list of 4 Patch
 objects)
 
 In [26]: hist(data, bins, align='center')
 Out[26]: (array([3, 1, 1, 1]), [0, 1, 2, 3], a list of 4 Patch
 objects)
 
 
 I would suspect that the histogram output from 'center' should be [2, 2,
 1, 1]. Why is this not so? At least, the two should be different? I
 would say that with edge, my bins would be 0-1, 1-2, 2-3, 3-4, and that
 center should give me -0.5-0.5, 0.5-1.5, 1.5-2.5, 2.5-3.5, but this
 seems not to be the case??? Any help understanding this would be greatly
 appreciated!

It seems that the hist function simply calls matplotlib.mlab.hist
without any regard to the bins (be they edge or centered values) and
passes the plotting through to the 'bar' function. This function places
the bar with either the edge at the bin value or the center at the bin
value. 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...

Thanks,

David


 
 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.phpp=sourceforgeCID=DEVDEV
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users
 


-
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.phpp=sourceforgeCID=DEVDEV
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users