call signature::
hist(x, bins=10, range=None, normed=False, cumulative=False,
bottom=None, histtype='bar', align='mid',
orientation='vertical', rwidth=None, log=False, **kwargs)
Compute and draw the histogram of *x*. The return value is a
tuple (*n*, *bins*, *patches*) or ([*n0*, *n1*, ...], *bins*,
[*patches0*, *patches1*,...]) if the input contains multiple
data.
Multiple data can be provided via *x* as a list of datasets
of potentially different length ([*x0*, *x1*, ...]), or as
a 2-D ndarray in which each column is a dataset. Note that
the ndarray form is transposed relative to the list form.
Masked arrays are not supported at present.
Keyword arguments:
*bins*:
Either an integer number of bins or a sequence giving the
bins. If *bins* is an integer, *bins* + 1 bin edges
will be returned, consistent with :func:`numpy.histogram`
for numpy version >= 1.3, and with the *new* = True argument
in earlier versions.
Unequally spaced bins are supported if *bins* is a sequence.
*range*:
The lower and upper range of the bins. Lower and upper outliers
are ignored. If not provided, *range* is (x.min(), x.max()).
Range has no effect if *bins* is a sequence.
If *bins* is a sequence or *range* is specified, autoscaling
is based on the specified bin range instead of the
range of x.
*normed*:
If *True*, the first element of the return tuple will
be the counts normalized to form a probability density, i.e.,
``n/(len(x)*dbin)``. In a probability density, the integral of
the histogram should be 1; you can verify that with a
trapezoidal integration of the probability density function::
pdf, bins, patches = ax.hist(...)
print np.sum(pdf * np.diff(bins))
.. Note:: Until numpy release 1.5, the underlying numpy
histogram function was incorrect with *normed*=*True*
if bin sizes were unequal. MPL inherited that
error. It is now corrected within MPL when using
earlier numpy versions
*weights*
An array of weights, of the same shape as *x*. Each value in
*x* only contributes its associated weight towards the bin
count (instead of 1). If *normed* is True, the weights are
normalized, so that the integral of the density over the range
remains 1.
*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 1. If *cumulative* evaluates to less than 0
(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 1.
*histtype*: [ 'bar' | 'barstacked' | 'step' | 'stepfilled' ]
The type of histogram to draw.
- 'bar' is a traditional bar-type histogram. If multiple data
are given the bars are aranged side by side.
- 'barstacked' is a bar-type histogram where multiple
data are stacked on top of each other.
- 'step' generates a lineplot that is by default
unfilled.
- 'stepfilled' generates a lineplot that is by default
filled.
*align*: ['left' | 'mid' | 'right' ]
Controls how the histogram is plotted.
- 'left': bars are centered on the left bin edges.
- 'mid': bars are centered between the bin edges.
- 'right': bars are centered on the right bin edges.
*orientation*: [ 'horizontal' | 'vertical' ]
If 'horizontal', :func:`~matplotlib.pyplot.barh` will be
used for bar-type histograms and the *bottom* kwarg will be
the left edges.
*rwidth*:
The relative width of the bars as a fraction of the bin
width. If *None*, automatically compute the width. Ignored
if *histtype* = 'step' or 'stepfilled'.
*log*:
If *True*, the histogram axis will be set to a log scale.
If *log* is *True* and *x* is a 1D array, empty bins will
be filtered out and only the non-empty (*n*, *bins*,
*patches*) will be returned.
*color*:
Color spec or sequence of color specs, one per
dataset. Default (*None*) uses the standard line
color sequence.
*label*:
String, or sequence of strings to match multiple
datasets. Bar charts yield multiple patches per
dataset, but only the first gets the label, so
that the legend command will work as expected::
ax.hist(10+2*np.random.randn(1000), label='men')
ax.hist(12+3*np.random.randn(1000), label='women', alpha=0.5)
ax.legend()
kwargs are used to update the properties of the
:class:`~matplotlib.patches.Patch` instances returned by *hist*:
%(Patch)s
**Example:**
.. plot:: mpl_examples/pylab_examples/histogram_demo.py
Definition at line 18 of file mpl_axes_hist_fix.py.
References python.LumiList.DeprecationWarning, cmsPerfStripChart.dict, objects.autophobj.float, is_sequence_of_strings, is_string_like, iterable, list(), hpstanc_transforms.max, min(), GetRecoTauVFromDQM_MC_cff.next, and ComparisonHelper.zip().
22 hist(x, bins=10, range=None, normed=False, cumulative=False, 23 bottom=None, histtype='bar', align='mid', 24 orientation='vertical', rwidth=None, log=False, **kwargs) 26 Compute and draw the histogram of *x*. The return value is a 27 tuple (*n*, *bins*, *patches*) or ([*n0*, *n1*, ...], *bins*, 28 [*patches0*, *patches1*,...]) if the input contains multiple 31 Multiple data can be provided via *x* as a list of datasets 32 of potentially different length ([*x0*, *x1*, ...]), or as 33 a 2-D ndarray in which each column is a dataset. Note that 34 the ndarray form is transposed relative to the list form. 36 Masked arrays are not supported at present. 41 Either an integer number of bins or a sequence giving the 42 bins. If *bins* is an integer, *bins* + 1 bin edges 43 will be returned, consistent with :func:`numpy.histogram` 44 for numpy version >= 1.3, and with the *new* = True argument 46 Unequally spaced bins are supported if *bins* is a sequence. 49 The lower and upper range of the bins. Lower and upper outliers 50 are ignored. If not provided, *range* is (x.min(), x.max()). 51 Range has no effect if *bins* is a sequence. 53 If *bins* is a sequence or *range* is specified, autoscaling 54 is based on the specified bin range instead of the 58 If *True*, the first element of the return tuple will 59 be the counts normalized to form a probability density, i.e., 60 ``n/(len(x)*dbin)``. In a probability density, the integral of 61 the histogram should be 1; you can verify that with a 62 trapezoidal integration of the probability density function:: 64 pdf, bins, patches = ax.hist(...) 65 print np.sum(pdf * np.diff(bins)) 67 .. Note:: Until numpy release 1.5, the underlying numpy 68 histogram function was incorrect with *normed*=*True* 69 if bin sizes were unequal. MPL inherited that 70 error. It is now corrected within MPL when using 71 earlier numpy versions 74 An array of weights, of the same shape as *x*. Each value in 75 *x* only contributes its associated weight towards the bin 76 count (instead of 1). If *normed* is True, the weights are 77 normalized, so that the integral of the density over the range 81 If *True*, then a histogram is computed where each bin 82 gives the counts in that bin plus all bins for smaller values. 83 The last bin gives the total number of datapoints. If *normed* 84 is also *True* then the histogram is normalized such that the 85 last bin equals 1. If *cumulative* evaluates to less than 0 86 (e.g. -1), the direction of accumulation is reversed. In this 87 case, if *normed* is also *True*, then the histogram is normalized 88 such that the first bin equals 1. 90 *histtype*: [ 'bar' | 'barstacked' | 'step' | 'stepfilled' ] 91 The type of histogram to draw. 93 - 'bar' is a traditional bar-type histogram. If multiple data 94 are given the bars are aranged side by side. 96 - 'barstacked' is a bar-type histogram where multiple 97 data are stacked on top of each other. 99 - 'step' generates a lineplot that is by default 102 - 'stepfilled' generates a lineplot that is by default 105 *align*: ['left' | 'mid' | 'right' ] 106 Controls how the histogram is plotted. 108 - 'left': bars are centered on the left bin edges. 110 - 'mid': bars are centered between the bin edges. 112 - 'right': bars are centered on the right bin edges. 114 *orientation*: [ 'horizontal' | 'vertical' ] 115 If 'horizontal', :func:`~matplotlib.pyplot.barh` will be 116 used for bar-type histograms and the *bottom* kwarg will be 120 The relative width of the bars as a fraction of the bin 121 width. If *None*, automatically compute the width. Ignored 122 if *histtype* = 'step' or 'stepfilled'. 125 If *True*, the histogram axis will be set to a log scale. 126 If *log* is *True* and *x* is a 1D array, empty bins will 127 be filtered out and only the non-empty (*n*, *bins*, 128 *patches*) will be returned. 131 Color spec or sequence of color specs, one per 132 dataset. Default (*None*) uses the standard line 136 String, or sequence of strings to match multiple 137 datasets. Bar charts yield multiple patches per 138 dataset, but only the first gets the label, so 139 that the legend command will work as expected:: 141 ax.hist(10+2*np.random.randn(1000), label='men') 142 ax.hist(12+3*np.random.randn(1000), label='women', alpha=0.5) 145 kwargs are used to update the properties of the 146 :class:`~matplotlib.patches.Patch` instances returned by *hist*: 152 .. plot:: mpl_examples/pylab_examples/histogram_demo.py 154 if not self._hold: self.cla()
161 if histtype
not in [
'bar',
'barstacked',
'step',
'stepfilled']:
162 raise ValueError(
"histtype %s is not recognized" % histtype)
164 if align
not in [
'left',
'mid',
'right']:
165 raise ValueError(
"align kwarg %s is not recognized" % align)
167 if orientation
not in [
'horizontal',
'vertical']:
169 "orientation kwarg %s is not recognized" % orientation)
172 if kwargs.get(
'width')
is not None:
174 'hist now uses the rwidth to give relative width ' 175 'and not absolute width')
179 if isinstance(x, np.ndarray)
or not iterable(x[0]):
185 x = x.reshape(1, x.shape[0])
187 raise ValueError(
"x must be 1D or 2D")
188 if x.shape[1] < x.shape[0]:
189 warnings.warn(
'2D hist input should be nsamples x nvariables;\n ' 190 'this looks transposed (shape is %d x %d)' % x.shape[::-1])
193 x = [np.array(xi)
for xi
in x]
198 color = [
next(self._get_lines.color_cycle)
201 color = mcolors.colorConverter.to_rgba_array(color)
203 raise ValueError(
"color kwarg must have one color per dataset")
206 if weights
is not None:
207 if isinstance(weights, np.ndarray)
or not iterable(weights[0]) :
208 w = np.array(weights)
212 w.shape = (1, w.shape[0])
214 raise ValueError(
"weights must be 1D or 2D")
216 w = [np.array(wi)
for wi
in weights]
219 raise ValueError(
'weights should have the same shape as x')
221 if len(w[i]) != len(x[i]):
223 'weights should have the same shape as x')
231 _saved_autoscalex = self.get_autoscalex_on()
232 _saved_autoscaley = self.get_autoscaley_on()
233 self.set_autoscalex_on(
False)
234 self.set_autoscaley_on(
False)
237 _saved_bounds = self.dataLim.bounds
241 binsgiven = (cbook.iterable(bins)
or range !=
None)
250 xmin =
min(xmin, xi.min())
251 xmax =
max(xmax, xi.max())
257 hist_kwargs =
dict(range=range)
258 if np.__version__ <
"1.3":
259 hist_kwargs[
'new'] =
True 265 m, bins = np.histogram(x[i], bins, weights=w[i], **hist_kwargs)
268 m = (m.astype(float) / db) / m.sum()
270 if normed
and db.std() > 0.01 * db.mean():
272 This release fixes a normalization bug in the NumPy histogram 273 function prior to version 1.5, occuring with non-uniform 274 bin widths. The returned and plotted value is now a density: 276 where n is the bin count and N the total number of points. 283 if cbook.is_numlike(cumulative)
and cumulative < 0:
284 slc = slice(
None,
None,-1)
287 n = [(m * np.diff(bins))[slc].cumsum()[slc]
for m
in n]
289 n = [m[slc].cumsum()[slc]
for m
in n]
293 if histtype.startswith(
'bar'):
294 totwidth = np.diff(bins)
296 if rwidth
is not None:
297 dr =
min(1.0,
max(0.0, rwidth))
304 width = dr*totwidth/nx
308 boffset = -0.5*dr*totwidth*(1.0-1.0/nx)
312 elif histtype==
'barstacked':
314 boffset, dw = 0.0, 0.0
317 if align ==
'mid' or align ==
'edge':
318 boffset += 0.5*totwidth
319 elif align ==
'right':
322 if orientation ==
'horizontal':
327 for m, c
in zip(n, color):
328 patch = _barfunc(bins[:-1]+boffset, m, width, bottom,
329 align=
'center', log=log,
331 patches.append(patch)
338 elif histtype.startswith(
'step'):
339 x = np.zeros( 2*len(bins), np.float )
340 y = np.zeros( 2*len(bins), np.float )
342 x[0::2], x[1::2] = bins, bins
355 if align ==
'left' or align ==
'center':
356 x -= 0.5*(bins[1]-bins[0])
357 elif align ==
'right':
358 x += 0.5*(bins[1]-bins[0])
361 y[0],y[-1] = minimum, minimum
362 if orientation ==
'horizontal':
363 self.set_xscale(
'log')
365 self.set_yscale(
'log')
367 fill = (histtype ==
'stepfilled')
369 for m, c
in zip(n, color):
370 y[1:-1:2], y[2::2] = m, m
373 if orientation ==
'horizontal':
377 patches.append( self.fill(x, y,
378 closed=
False, facecolor=c) )
380 patches.append( self.fill(x, y,
381 closed=
False, edgecolor=c, fill=
False) )
384 if orientation ==
'horizontal':
385 xmin0 =
max(_saved_bounds[0]*0.9, minimum)
386 xmax = self.dataLim.intervalx[1]
388 xmin = np.amin(m[m!=0])
389 xmin =
max(xmin*0.9, minimum)
390 xmin =
min(xmin0, xmin)
391 self.dataLim.intervalx = (xmin, xmax)
392 elif orientation ==
'vertical':
393 ymin0 =
max(_saved_bounds[1]*0.9, minimum)
394 ymax = self.dataLim.intervaly[1]
396 ymin = np.amin(m[m!=0])
397 ymin =
max(ymin*0.9, minimum)
398 ymin =
min(ymin0, ymin)
399 self.dataLim.intervaly = (ymin, ymax)
402 labels = [
'_nolegend_']
409 'invalid label: must be string or sequence of strings')
411 labels += [
'_nolegend_'] * (nx - len(labels))
413 for (patch, lbl)
in zip(patches, labels):
420 if orientation ==
'vertical':
421 self.update_datalim([(bins[0],0), (bins[-1],0)], updatey=
False)
423 self.update_datalim([(0,bins[0]), (0,bins[-1])], updatex=
False)
425 self.set_autoscalex_on(_saved_autoscalex)
426 self.set_autoscaley_on(_saved_autoscaley)
427 self.autoscale_view()
430 return n[0], bins, cbook.silent_list(
'Patch', patches[0])
432 return n, bins, cbook.silent_list(
'Lists of Patches', patches)
433
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run