Revision: 5147
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5147&view=rev
Author:   mmetz_bn
Date:     2008-05-16 07:52:15 -0700 (Fri, 16 May 2008)

Log Message:
-----------
added cumulative histograms

Modified Paths:
--------------
    trunk/matplotlib/CHANGELOG
    trunk/matplotlib/lib/matplotlib/axes.py

Added Paths:
-----------
    trunk/matplotlib/examples/histogram_demo_cumulative.py

Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG  2008-05-16 13:41:25 UTC (rev 5146)
+++ trunk/matplotlib/CHANGELOG  2008-05-16 14:52:15 UTC (rev 5147)
@@ -1,3 +1,7 @@
+2008-05-16 Added 'cumulative' keyword arg to hist to plot cumulative
+           histograms. For normed hists, this is normalized to one
+           assuming equally spaced bins - MM
+
 2008-05-15 Fix Tk backend segfault on some machines - MGD
 
 2008-05-14 Don't use stat on Windows (fixes font embedding problem) - MGD

Added: trunk/matplotlib/examples/histogram_demo_cumulative.py
===================================================================
--- trunk/matplotlib/examples/histogram_demo_cumulative.py                      
        (rev 0)
+++ trunk/matplotlib/examples/histogram_demo_cumulative.py      2008-05-16 
14:52:15 UTC (rev 5147)
@@ -0,0 +1,33 @@
+#!/usr/bin/env python
+from pylab import *
+
+mu, sigma = 100, 25
+x = mu + sigma*randn(10000)
+
+# the histogram of the data
+n, bins, patches = hist(x, 50, normed=1, histtype='step', cumulative=True)
+setp(patches, 'facecolor', 'g', 'alpha', 0.75)
+
+# add a 'best fit' line
+y = normpdf( bins, mu, sigma).cumsum()
+y /= y[-1]
+l = plot(bins, y, 'k--', linewidth=1.5)
+
+# overlay the first histogram with a second one
+# were the data has a smaller standard deviation
+mu, sigma = 100, 10
+x = mu + sigma*randn(10000)
+
+n, bins, patches = hist(x, bins=bins, normed=1, histtype='step', 
cumulative=True)
+setp(patches, 'facecolor', 'r', 'alpha', 0.25)
+
+# add a 'best fit' line
+y = normpdf( bins, mu, sigma).cumsum()
+y /= y[-1]
+l = plot(bins, y, 'k--', linewidth=1.5)
+
+grid(True)
+ylim(0, 1.1)
+
+#savefig('histogram_demo',dpi=72)
+show()
\ No newline at end of file

Modified: trunk/matplotlib/lib/matplotlib/axes.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/axes.py     2008-05-16 13:41:25 UTC (rev 
5146)
+++ trunk/matplotlib/lib/matplotlib/axes.py     2008-05-16 14:52:15 UTC (rev 
5147)
@@ -5416,9 +5416,9 @@
     #### Data analysis
 
 
-    def hist(self, x, bins=10, normed=False, bottom=None, histtype='bar',
-             align='edge', orientation='vertical', width=None,
-             log=False, **kwargs):
+    def hist(self, x, bins=10, normed=False, cumulative=False,
+             bottom=None, histtype='bar', align='edge',
+             orientation='vertical', width=None, log=False, **kwargs):
         """
         HIST(x, bins=10, normed=False, bottom=None, histtype='bar',
              align='edge', orientation='vertical', width=None,
@@ -5439,6 +5439,12 @@
           pdf, bins, patches = ax.hist(...)
           print np.trapz(pdf, bins)
 
+        If cumulative is True then histogram is computed where each bin
+        gives the counts in that bin plus all bins for smaller values.
+        The last bins gives the total number of datapoints.  If normed is
+        also True then the histogram is normalized such that the last bin
+        equals one (assuming equally spaced bins).
+
         histtype = 'bar' | 'step'. The type of histogram to draw.
         'bar' is a traditional bar-type histogram, 'step' generates
         a lineplot.
@@ -5461,6 +5467,12 @@
         if not self._hold: self.cla()
         n, bins = np.histogram(x, bins, range=None,
             normed=bool(normed), new=True)
+        
+        if cumulative:
+            n = n.cumsum()
+            if normed:
+                # normalize to 1
+                n *= (bins[1]-bins[0])
 
         if histtype == 'bar':
             if width is None:


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft 
Defy all challenges. Microsoft(R) Visual Studio 2008. 
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to