Revision: 5411
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5411&view=rev
Author: mmetz_bn
Date: 2008-06-06 09:34:00 -0700 (Fri, 06 Jun 2008)
Log Message:
-----------
a further hist() update
Modified Paths:
--------------
trunk/matplotlib/CHANGELOG
trunk/matplotlib/examples/pylab_examples/histogram_demo_extended.py
trunk/matplotlib/lib/matplotlib/axes.py
Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG 2008-06-06 12:57:24 UTC (rev 5410)
+++ trunk/matplotlib/CHANGELOG 2008-06-06 16:34:00 UTC (rev 5411)
@@ -1,3 +1,9 @@
+2008-06-06 hist() revision, applied ideas proposed by Erik Tollerud and
+ Olle Engdegard: make histtype='step' unfilled by default
+ and introduce histtype='stepfilled'; use default color
+ cycle; introduce reverse cumulative histogram; new align
+ keyword - MM
+
2008-06-06 Fix closed polygon patch and also provide the option to
not close the polygon - MGD
Modified: trunk/matplotlib/examples/pylab_examples/histogram_demo_extended.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/histogram_demo_extended.py
2008-06-06 12:57:24 UTC (rev 5410)
+++ trunk/matplotlib/examples/pylab_examples/histogram_demo_extended.py
2008-06-06 16:34:00 UTC (rev 5411)
@@ -12,7 +12,7 @@
x = mu + sigma*P.randn(10000)
# the histogram of the data with histtype='step'
-n, bins, patches = P.hist(x, 50, normed=1, histtype='step')
+n, bins, patches = P.hist(x, 50, normed=1, histtype='stepfilled')
P.setp(patches, 'facecolor', 'g', 'alpha', 0.75)
# add a line showing the expected distribution
@@ -35,7 +35,6 @@
P.figure()
n, bins, patches = P.hist(x, 50, normed=1, histtype='step', cumulative=True)
-P.setp(patches, 'facecolor', 'b', 'alpha', 0.75)
# add a line showing the expected distribution
y = P.normpdf( bins, mu, sigma).cumsum()
@@ -47,13 +46,17 @@
x = mu + sigma2*P.randn(10000)
n, bins, patches = P.hist(x, bins=bins, normed=1, histtype='step',
cumulative=True)
-P.setp(patches, 'facecolor', 'r', 'alpha', 0.5)
# add a line showing the expected distribution
y = P.normpdf( bins, mu, sigma2).cumsum()
y /= y[-1]
l = P.plot(bins, y, 'r--', linewidth=1.5)
+# finally overplot a reverted cumulative histogram
+n, bins, patches = P.hist(x, bins=bins, normed=1,
+ histtype='step', cumulative=-1)
+
+
P.grid(True)
P.ylim(0, 1.05)
Modified: trunk/matplotlib/lib/matplotlib/axes.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/axes.py 2008-06-06 12:57:24 UTC (rev
5410)
+++ trunk/matplotlib/lib/matplotlib/axes.py 2008-06-06 16:34:00 UTC (rev
5411)
@@ -5634,7 +5634,7 @@
def hist(self, x, bins=10, normed=False, cumulative=False,
- bottom=None, histtype='bar', align='edge',
+ bottom=None, histtype='bar', align='mid',
orientation='vertical', rwidth=None, log=False, **kwargs):
"""
call signature::
@@ -5667,20 +5667,26 @@
cumulative:
if True then a histogram is computed where each bin
gives the counts in that bin plus all bins for smaller values.
- The last bin gives the total number of datapoints. If normed is
- also True then the histogram is normalized such that the last bin
- equals one.
+ The last bin gives the total number of datapoints. If normed
+ is also True then the histogram is normalized such that the
+ last bin equals one. If cumulative evaluates to less that one
+ (e.g. -1), the direction of accumulation is reversed. In this
+ case, If normed is also True then the histogram is normalized
+ such that the first bin equals one.
histtype:
- [ 'bar' | 'barstacked' | 'step' ] The type of histogram
- to draw. 'bar' is a traditional bar-type histogram,
+ [ 'bar' | 'barstacked' | 'step' | 'stepfilled' ] The type of
+ histogram to draw. 'bar' is a traditional bar-type histogram,
'barstacked' is a bar-type histogram where multiple data are
- stacked on top of each other, and 'step' generates a lineplot.
+ stacked on top of each other. step' generates a lineplot that
+ is by default unfilled, and 'stepfilled' generates a lineplot
+ that this by default filled.
align:
- ['edge' | 'center' ] Controles how the histogram is plotted.
- If 'edge', bars are centered between the bin edges.
- If 'center', bars are centered on the left bin edges
+ ['left' | 'mid' | 'right' ] Controles how the histogram is
+ plotted. If 'left', bars are centered on the left bin edges.
+ If 'mid', bars are centered between the bin edges. If 'right',
+ bars are centered on the right bin edges.
orientation:
[ 'horizontal' | 'vertical' ] If horizontal, barh will be used
@@ -5716,7 +5722,6 @@
warnings.warn('2D hist should be nsamples x nvariables; this looks
transposed')
if len(x.shape)==2:
-
n = []
for i in xrange(x.shape[1]):
# this will automatically overwrite bins,
@@ -5730,13 +5735,16 @@
n = [n,]
if cumulative:
+ slc = slice(None)
+ if cbook.is_numlike(cumulative):
+ if cumulative < 0:
+ slc = slice(None,None,-1)
+
if normed:
- n = [(m * np.diff(bins)).cumsum() for m in n]
+ n = [(m * np.diff(bins))[slc].cumsum()[slc] for m in n]
else:
- n = [m.cumsum() for m in n]
+ n = [m[slc].cumsum()[slc] for m in n]
- ccount = 0
- colors = _process_plot_var_args.defaultColors[:]
patches = []
if histtype.startswith('bar'):
@@ -5763,14 +5771,16 @@
else:
raise ValueError, 'invalid histtype: %s' % histtype
- if align=='edge':
+ if align == 'mid' or align == 'edge':
boffset += 0.5*totwidth
- elif align != 'center':
+ elif align == 'right':
+ boffset += totwidth
+ elif align != 'left' and align != 'center':
raise ValueError, 'invalid align: %s' % align
if orientation == 'horizontal':
for m in n:
- color = colors[ccount % len(colors)]
+ color = self._get_lines._get_next_cycle_color()
patch = self.barh(bins[:-1]+boffset, m, height=width,
left=bottom, align='center', log=log,
color=color)
@@ -5779,10 +5789,9 @@
if bottom is None: bottom = 0.0
bottom += m
boffset += dw
- ccount += 1
elif orientation == 'vertical':
for m in n:
- color = colors[ccount % len(colors)]
+ color = self._get_lines._get_next_cycle_color()
patch = self.bar(bins[:-1]+boffset, m, width=width,
bottom=bottom, align='center', log=log,
color=color)
@@ -5791,19 +5800,20 @@
if bottom is None: bottom = 0.0
bottom += m
boffset += dw
- ccount += 1
else:
raise ValueError, 'invalid orientation: %s' % orientation
- elif histtype == 'step':
+ elif histtype.startswith('step'):
x = np.zeros( 2*len(bins), np.float_ )
y = np.zeros( 2*len(bins), np.float_ )
x[0::2], x[1::2] = bins, bins
- if align == 'center':
+ if align == 'left' or align == 'center':
x -= 0.5*(bins[1]-bins[0])
- elif align != 'edge':
+ elif align == 'right':
+ x += 0.5*(bins[1]-bins[0])
+ elif align != 'mid' and align != 'edge':
raise ValueError, 'invalid align: %s' % align
if log:
@@ -5812,6 +5822,12 @@
self.set_xscale('log')
elif orientation == 'vertical':
self.set_yscale('log')
+
+ fill = False
+ if histtype == 'stepfilled':
+ fill = True
+ elif histtype != 'step':
+ raise ValueError, 'invalid histtype: %s' % histtype
for m in n:
y[1:-1:2], y[2::2] = m, m
@@ -5819,7 +5835,14 @@
x,y = y,x
elif orientation != 'vertical':
raise ValueError, 'invalid orientation: %s' % orientation
- patches.append( self.fill(x,y,closed=False) )
+
+ color = self._get_lines._get_next_cycle_color()
+ if fill:
+ patches.append( self.fill(x, y,
+ closed=False, facecolor=color) )
+ else:
+ patches.append( self.fill(x, y,
+ closed=False, edgecolor=color, fill=False) )
# adopted from adjust_x/ylim part of the bar method
if orientation == 'horizontal':
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins