From 7ba17436d03aa59b5964147633016146ed46a7dc Mon Sep 17 00:00:00 2001 From: Nic Eggert Date: Fri, 24 Aug 2012 17:35:15 -0400 Subject: [PATCH 1/6] Add stacked kwarg to hist. This allows stacked step and stepfilled hists. --- .../pylab_examples/histogram_demo_extended.py | 14 +- lib/matplotlib/axes.py | 38 +- .../test_axes/hist_stacked.pdf | Bin 0 -> 5514 bytes .../test_axes/hist_stacked.png | Bin 0 -> 5992 bytes .../test_axes/hist_stacked.svg | 558 ++++++++++++++++++ lib/matplotlib/tests/test_axes.py | 9 + 6 files changed, 608 insertions(+), 11 deletions(-) create mode 100644 lib/matplotlib/tests/baseline_images/test_axes/hist_stacked.pdf create mode 100644 lib/matplotlib/tests/baseline_images/test_axes/hist_stacked.png create mode 100644 lib/matplotlib/tests/baseline_images/test_axes/hist_stacked.svg diff --git a/examples/pylab_examples/histogram_demo_extended.py b/examples/pylab_examples/histogram_demo_extended.py index 966cc7aaf32d..df8404385b2f 100644 --- a/examples/pylab_examples/histogram_demo_extended.py +++ b/examples/pylab_examples/histogram_demo_extended.py @@ -82,7 +82,19 @@ # P.figure() -n, bins, patches = P.hist(x, 10, normed=1, histtype='barstacked') +n, bins, patches = P.hist(x, 10, normed=1, histtype='bar', stacked=True) + +P.show() + +# +# we can also stack using the step histtype +# + +P.figure() + +n, bins, patches = P.hist(x, 10, histtype='step', stacked=True, fill=True) + +P.show() # # finally: make a multiple-histogram of data-sets with different length diff --git a/lib/matplotlib/axes.py b/lib/matplotlib/axes.py index c6115693d38e..91460ac7a1c7 100644 --- a/lib/matplotlib/axes.py +++ b/lib/matplotlib/axes.py @@ -7728,7 +7728,7 @@ def get_shared_y_axes(self): def hist(self, x, bins=10, range=None, normed=False, weights=None, cumulative=False, bottom=None, histtype='bar', align='mid', orientation='vertical', rwidth=None, log=False, - color=None, label=None, + color=None, label=None, stacked=False, **kwargs): """ Plot a histogram. @@ -7738,7 +7738,7 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, hist(x, bins=10, range=None, normed=False, weights=None, cumulative=False, bottom=None, histtype='bar', align='mid', orientation='vertical', rwidth=None, log=False, - color=None, label=None, + color=None, label=None, stacked=False, **kwargs) Compute and draw the histogram of *x*. The return value is a @@ -7862,6 +7862,11 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, ax.hist(12+3*np.random.randn(1000), label='women', alpha=0.5) ax.legend() + *stacked*: + If *True*, multiple data are stacked on top of each other + If *False* multiple data are aranged side by side if + histtype is 'bar' or on top of each other if histtype is 'step' + . kwargs are used to update the properties of the @@ -7901,6 +7906,9 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, 'hist now uses the rwidth to give relative width ' 'and not absolute width') + if histtype == 'barstacked' and not stacked: + stacked=True + # Massage 'x' for processing. # NOTE: Be sure any changes here is also done below to 'weights' if isinstance(x, np.ndarray) or not iterable(x[0]): @@ -7919,6 +7927,8 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, # multiple hist with data of different length x = [np.asarray(xi) for xi in x] + x = x[::-1] # reverse datasets for caculating stacked hist + nx = len(x) # number of datasets if color is None: @@ -7942,6 +7952,8 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, else: w = [np.asarray(wi) for wi in weights] + w = w[::-1] # reverse weights to match datasets + if len(w) != nx: raise ValueError('weights should have the same shape as x') for i in xrange(nx): @@ -7986,13 +7998,19 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, hist_kwargs['new'] = True n = [] + mlast = bottom for i in xrange(nx): # this will automatically overwrite bins, # so that each histogram uses the same bins m, bins = np.histogram(x[i], bins, weights=w[i], **hist_kwargs) + if mlast == None : + mlast = np.zeros(len(bins)-1, np.int) if normed: db = np.diff(bins) m = (m.astype(float) / db) / m.sum() + if stacked : + m += mlast + mlast[:] = m n.append(m) if cumulative: @@ -8005,6 +8023,9 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, else: n = [m[slc].cumsum()[slc] for m in n] + if stacked : + n.reverse() # put them back in the right order + patches = [] if histtype.startswith('bar'): @@ -8017,7 +8038,7 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, else: dr = 1.0 - if histtype=='bar': + if histtype=='bar' and not stacked: width = dr*totwidth/nx dw = width @@ -8026,10 +8047,9 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, else: boffset = 0.0 stacked = False - elif histtype=='barstacked': + elif histtype=='barstacked' or stacked: width = dr*totwidth boffset, dw = 0.0, 0.0 - stacked = True if align == 'mid' or align == 'edge': boffset += 0.5*totwidth @@ -8042,14 +8062,10 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, _barfunc = self.bar for m, c in zip(n, color): - patch = _barfunc(bins[:-1]+boffset, m, width, bottom, + patch = _barfunc(bins[:-1]+boffset, m, width, align='center', log=log, color=c) patches.append(patch) - if stacked: - if bottom is None: - bottom = 0.0 - bottom += m boffset += dw elif histtype.startswith('step'): @@ -8072,6 +8088,8 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, else: # orientation == 'vertical' self.set_yscale('log') + # If fill kwarg is set, it will be passed to the patch collection, + # overriding this fill = (histtype == 'stepfilled') for m, c in zip(n, color): diff --git a/lib/matplotlib/tests/baseline_images/test_axes/hist_stacked.pdf b/lib/matplotlib/tests/baseline_images/test_axes/hist_stacked.pdf new file mode 100644 index 0000000000000000000000000000000000000000..cc60f693d67f0d1e06dc5e22072598c1dd6b7305 GIT binary patch literal 5514 zcmb_g3s@7^@(0C&0n5XNE6U}rXhe#TWRuMU1O);}c@qoxp-6xPf{=t{K?J2D_`r&y zg5m?L#Rn8A57ANu#Zr)miXgsL|;<*F$!ektwdd35_ zE+eDs$mofzK&WoXxCb8>;6j9{QoxT9M2RKQ2ur2jT`Iv5266q)96Aj!)DC#arHL{G zy5h=5s61hkI8qqs0Tu&yOXUKILMD(4C6Q~?uBzmnoS?7Z0j_eEMD-Cyi3KjwWMDc} zkFi+@lYv4T1BD7{qC67d0&xgbD}qpgMS+1pivr;i&)yjc@6|TCi{k)D2-Q6fc*+w- zN~6F`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ou|?e-QU`IAxBW_-ljyy*UR z{e$zxxue_{yiuK+daYjtTtwT|n4Tl`<90XtbsF*fg;M6No@yP77A + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index de7fb8bcb020..337f02724e93 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -856,6 +856,15 @@ def test_errorbar(): fig.suptitle('Variable errorbars') +@image_comparison(baseline_images=['hist_stacked']) +def test_hist_stacked(): + # make some data + d1 = np.linspace(0, 10, 50) + d2 = np.linspace(1, 3, 20) + fig = plt.figure() + ax = fig.add_subplot(111) + ax.hist( (d1, d2), histtype="stepfilled", stacked=True) + if __name__=='__main__': import nose nose.runmodule(argv=['-s','--with-doctest'], exit=False) From e12e3c40114d17ee31681a4039d5d74261fe0310 Mon Sep 17 00:00:00 2001 From: Nic Eggert Date: Fri, 24 Aug 2012 15:47:35 -0400 Subject: [PATCH 2/6] Clean up a few style issues --- lib/matplotlib/axes.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/axes.py b/lib/matplotlib/axes.py index 91460ac7a1c7..811036bca6da 100644 --- a/lib/matplotlib/axes.py +++ b/lib/matplotlib/axes.py @@ -8003,12 +8003,12 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, # this will automatically overwrite bins, # so that each histogram uses the same bins m, bins = np.histogram(x[i], bins, weights=w[i], **hist_kwargs) - if mlast == None : + if mlast is None: mlast = np.zeros(len(bins)-1, np.int) if normed: db = np.diff(bins) m = (m.astype(float) / db) / m.sum() - if stacked : + if stacked: m += mlast mlast[:] = m n.append(m) @@ -8023,7 +8023,7 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, else: n = [m[slc].cumsum()[slc] for m in n] - if stacked : + if stacked: n.reverse() # put them back in the right order patches = [] From 248ecfc40cd56152377b3e6b9fef1a541835730b Mon Sep 17 00:00:00 2001 From: Nic Eggert Date: Fri, 24 Aug 2012 19:11:55 -0400 Subject: [PATCH 3/6] Iterate through datasets in the reverse order instead of reversing the dataset list --- lib/matplotlib/axes.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/matplotlib/axes.py b/lib/matplotlib/axes.py index 811036bca6da..49f0c70914d7 100644 --- a/lib/matplotlib/axes.py +++ b/lib/matplotlib/axes.py @@ -7927,8 +7927,6 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, # multiple hist with data of different length x = [np.asarray(xi) for xi in x] - x = x[::-1] # reverse datasets for caculating stacked hist - nx = len(x) # number of datasets if color is None: @@ -7952,8 +7950,6 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, else: w = [np.asarray(wi) for wi in weights] - w = w[::-1] # reverse weights to match datasets - if len(w) != nx: raise ValueError('weights should have the same shape as x') for i in xrange(nx): @@ -7999,7 +7995,9 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, n = [] mlast = bottom - for i in xrange(nx): + # reversed order is necessary so when stacking histogram, first dataset is on top + # if histogram isn't stacked, this doesn't make any difference + for i in reversed(xrange(nx)): # this will automatically overwrite bins, # so that each histogram uses the same bins m, bins = np.histogram(x[i], bins, weights=w[i], **hist_kwargs) @@ -8023,8 +8021,7 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, else: n = [m[slc].cumsum()[slc] for m in n] - if stacked: - n.reverse() # put them back in the right order + n.reverse() # put them back in the right order patches = [] From 7c5e9fc2b9f1efa1da45ee0189eb39def9db4848 Mon Sep 17 00:00:00 2001 From: Nic Eggert Date: Tue, 4 Sep 2012 21:59:36 -0400 Subject: [PATCH 4/6] Updated pyplot.py to reflect new stacked argument in axes.hist --- lib/matplotlib/pyplot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index dcd46f87beb6..d4218ad40b41 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -2642,7 +2642,8 @@ def hexbin(x, y, C=None, gridsize=100, bins=None, xscale='linear', @_autogen_docstring(Axes.hist) def hist(x, bins=10, range=None, normed=False, weights=None, cumulative=False, bottom=None, histtype='bar', align='mid', orientation='vertical', - rwidth=None, log=False, color=None, label=None, hold=None, **kwargs): + rwidth=None, log=False, color=None, label=None, stacked=False, + hold=None, **kwargs): ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() From 77c5978c9fff9c15fc1b8f2296f1b37f8e5b79a0 Mon Sep 17 00:00:00 2001 From: Nic Eggert Date: Tue, 4 Sep 2012 22:06:24 -0400 Subject: [PATCH 5/6] Updated whats_new.rst to document new stacked hist feature --- doc/users/whats_new.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/doc/users/whats_new.rst b/doc/users/whats_new.rst index 0443dffdfc2c..d8cfadb9e269 100644 --- a/doc/users/whats_new.rst +++ b/doc/users/whats_new.rst @@ -127,6 +127,16 @@ local intensity of the vector field. .. plot:: mpl_examples/pylab_examples/streamplot_demo.py + +New hist functionality +---------------------- + +Nic Eggert added a new `stack kwarg to :meth:`~matplotlib.pyplot.hist` that +allows creation of stacked histograms using any of the histogram types. +Previously, this functionality was only available by using the `barstacked` +histogram type. Now, when `stacked=True` is passed to the function, any of the +histogram types can be stacked. + Updated shipped dependencies ---------------------------- From 242ecacc58c26a65b8694ee0175a4e380846e149 Mon Sep 17 00:00:00 2001 From: Nic Eggert Date: Wed, 5 Sep 2012 08:24:04 -0400 Subject: [PATCH 6/6] Fixed a typo ane expanded whats_new.rst on stacked histogram --- doc/users/whats_new.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/users/whats_new.rst b/doc/users/whats_new.rst index d8cfadb9e269..73f58ce98373 100644 --- a/doc/users/whats_new.rst +++ b/doc/users/whats_new.rst @@ -131,11 +131,12 @@ local intensity of the vector field. New hist functionality ---------------------- -Nic Eggert added a new `stack kwarg to :meth:`~matplotlib.pyplot.hist` that +Nic Eggert added a new `stacked` kwarg to :meth:`~matplotlib.pyplot.hist` that allows creation of stacked histograms using any of the histogram types. Previously, this functionality was only available by using the `barstacked` histogram type. Now, when `stacked=True` is passed to the function, any of the -histogram types can be stacked. +histogram types can be stacked. The `barstacked` histogram type retains its +previous functionality for backwards compatibility. Updated shipped dependencies ----------------------------