|
From: <mme...@us...> - 2008-08-28 13:50:42
|
Revision: 6055
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6055&view=rev
Author: mmetz_bn
Date: 2008-08-28 13:50:39 +0000 (Thu, 28 Aug 2008)
Log Message:
-----------
support for multi-hist with different length
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-08-28 13:12:46 UTC (rev 6054)
+++ trunk/matplotlib/CHANGELOG 2008-08-28 13:50:39 UTC (rev 6055)
@@ -1,3 +1,6 @@
+2008-08-28 Added support for multiple histograms with data of
+ different length - MM
+
2008-08-28 Fix step plots with log scale - MGD
2008-08-28 Fix masked arrays with markers in non-Agg backends - MGD
Modified: trunk/matplotlib/examples/pylab_examples/histogram_demo_extended.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/histogram_demo_extended.py 2008-08-28 13:12:46 UTC (rev 6054)
+++ trunk/matplotlib/examples/pylab_examples/histogram_demo_extended.py 2008-08-28 13:50:39 UTC (rev 6055)
@@ -78,5 +78,16 @@
n, bins, patches = P.hist(x, 10, normed=1, histtype='barstacked')
+#
+# finally: make a multiple-histogram of data-sets with different length
+#
+x0 = mu + sigma*P.randn(10000)
+x1 = mu + sigma*P.randn(7000)
+x2 = mu + sigma*P.randn(3000)
+P.figure()
+
+n, bins, patches = P.hist( [x0,x1,x2], 10, histtype='bar')
+
+
P.show()
\ No newline at end of file
Modified: trunk/matplotlib/lib/matplotlib/axes.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/axes.py 2008-08-28 13:12:46 UTC (rev 6054)
+++ trunk/matplotlib/lib/matplotlib/axes.py 2008-08-28 13:50:39 UTC (rev 6055)
@@ -6157,7 +6157,7 @@
- 'step' generates a lineplot that is by default
unfilled
- - 'stepfilled' generates a lineplot that this by default
+ - 'stepfilled' generates a lineplot that is by default
filled.
*align*: ['left' | 'mid' | 'right' ]
@@ -6209,26 +6209,27 @@
raise DeprecationWarning(
'hist now uses the rwidth to give relative width and not absolute width')
- # todo: make hist() work with list of arrays with different lengths
- x = np.asarray(x).copy()
- if len(x.shape)==2 and min(x.shape)==1:
- x.shape = max(x.shape),
+ try:
+ x = np.transpose(np.asarray(x).copy())
+ if len(x.shape)==1:
+ x.shape = (1,x.shape[0])
+ elif len(x.shape)==2 and x.shape[1]<x.shape[0]:
+ warnings.warn('2D hist should be nsamples x nvariables; this looks transposed')
+ except ValueError:
+ # multiple hist with data of different length
+ if iterable(x[0]) and not is_string_like(x[0]):
+ tx = []
+ for i in xrange(len(x)):
+ tx.append( np.asarray(x[i]).copy() )
+ x = tx
- if len(x.shape)==2 and x.shape[0]<x.shape[1]:
- 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,
- # so that each histogram uses the same bins
- m, bins = np.histogram(x[:,i], bins, range=range,
- normed=bool(normed), new=True)
- n.append(m)
- else:
- n, bins = np.histogram(x, bins, range=range,
+ n = []
+ for i in xrange(len(x)):
+ # this will automatically overwrite bins,
+ # so that each histogram uses the same bins
+ m, bins = np.histogram(x[i], bins, range=range,
normed=bool(normed), new=True)
- n = [n,]
+ n.append(m)
if cumulative:
slc = slice(None)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|