From f9b6439f59edfd3167073006a25bf6a59db259b4 Mon Sep 17 00:00:00 2001 From: Shane Breeze Date: Thu, 27 Sep 2018 14:38:14 +0100 Subject: [PATCH] Add ishistogammed option to the plotting method --- lib/matplotlib/axes/_axes.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index e684d93bb5d8..2f39501f01ed 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -6256,6 +6256,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None, cumulative=False, bottom=None, histtype='bar', align='mid', orientation='vertical', rwidth=None, log=False, color=None, label=None, stacked=False, normed=None, + ishistogrammed=False, **kwargs): """ Plot a histogram. @@ -6430,6 +6431,13 @@ def hist(self, x, bins=None, range=None, density=None, weights=None, normed : bool, optional Deprecated; use the density keyword argument instead. + ishistogrammed : bool, optional + If ``True``, interpret the input data ``x`` as already histogrammed + data, preventing this method from preforming the histogramming. If + ``True``, the argument ``bins`` must also be provided. + + Default is ``False`` + Returns ------- n : array or list of arrays @@ -6497,6 +6505,10 @@ def hist(self, x, bins=None, range=None, density=None, weights=None, cbook.warn_deprecated("2.1", name="'normed'", obj_type="kwarg", alternative="'density'", removal="3.1") + if ishistogrammed and bins is None: + raise ValueError("'bins' must be passed if 'ishistogrammed' is " + "True.") + # basic input validation input_empty = np.size(x) == 0 # Massage 'x' for processing. @@ -6565,7 +6577,10 @@ def hist(self, x, bins=None, range=None, density=None, weights=None, for i in range(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 ishistogrammed: + m, bins = x[i], bins + else: + m, bins = np.histogram(x[i], bins, weights=w[i], **hist_kwargs) m = m.astype(float) # causes problems later if it's an int if mlast is None: mlast = np.zeros(len(bins)-1, m.dtype)