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.multivaluedict.dict, is_sequence_of_strings, is_string_like, iterable, list(), bookConverter.max, min(), and archive.zip.
23 hist(x, bins=10, range=None, normed=False, cumulative=False,
24 bottom=None, histtype='bar', align='mid',
25 orientation='vertical', rwidth=None, log=False, **kwargs)
27 Compute and draw the histogram of *x*. The return value is a
28 tuple (*n*, *bins*, *patches*) or ([*n0*, *n1*, ...], *bins*,
29 [*patches0*, *patches1*,...]) if the input contains multiple
32 Multiple data can be provided via *x* as a list of datasets
33 of potentially different length ([*x0*, *x1*, ...]), or as
34 a 2-D ndarray in which each column is a dataset. Note that
35 the ndarray form is transposed relative to the list form.
37 Masked arrays are not supported at present.
42 Either an integer number of bins or a sequence giving the
43 bins. If *bins* is an integer, *bins* + 1 bin edges
44 will be returned, consistent with :func:`numpy.histogram`
45 for numpy version >= 1.3, and with the *new* = True argument
47 Unequally spaced bins are supported if *bins* is a sequence.
50 The lower and upper range of the bins. Lower and upper outliers
51 are ignored. If not provided, *range* is (x.min(), x.max()).
52 Range has no effect if *bins* is a sequence.
54 If *bins* is a sequence or *range* is specified, autoscaling
55 is based on the specified bin range instead of the
59 If *True*, the first element of the return tuple will
60 be the counts normalized to form a probability density, i.e.,
61 ``n/(len(x)*dbin)``. In a probability density, the integral of
62 the histogram should be 1; you can verify that with a
63 trapezoidal integration of the probability density function::
65 pdf, bins, patches = ax.hist(...)
66 print np.sum(pdf * np.diff(bins))
68 .. Note:: Until numpy release 1.5, the underlying numpy
69 histogram function was incorrect with *normed*=*True*
70 if bin sizes were unequal. MPL inherited that
71 error. It is now corrected within MPL when using
72 earlier numpy versions
75 An array of weights, of the same shape as *x*. Each value in
76 *x* only contributes its associated weight towards the bin
77 count (instead of 1). If *normed* is True, the weights are
78 normalized, so that the integral of the density over the range
82 If *True*, then a histogram is computed where each bin
83 gives the counts in that bin plus all bins for smaller values.
84 The last bin gives the total number of datapoints. If *normed*
85 is also *True* then the histogram is normalized such that the
86 last bin equals 1. If *cumulative* evaluates to less than 0
87 (e.g. -1), the direction of accumulation is reversed. In this
88 case, if *normed* is also *True*, then the histogram is normalized
89 such that the first bin equals 1.
91 *histtype*: [ 'bar' | 'barstacked' | 'step' | 'stepfilled' ]
92 The type of histogram to draw.
94 - 'bar' is a traditional bar-type histogram. If multiple data
95 are given the bars are aranged side by side.
97 - 'barstacked' is a bar-type histogram where multiple
98 data are stacked on top of each other.
100 - 'step' generates a lineplot that is by default
103 - 'stepfilled' generates a lineplot that is by default
106 *align*: ['left' | 'mid' | 'right' ]
107 Controls how the histogram is plotted.
109 - 'left': bars are centered on the left bin edges.
111 - 'mid': bars are centered between the bin edges.
113 - 'right': bars are centered on the right bin edges.
115 *orientation*: [ 'horizontal' | 'vertical' ]
116 If 'horizontal', :func:`~matplotlib.pyplot.barh` will be
117 used for bar-type histograms and the *bottom* kwarg will be
121 The relative width of the bars as a fraction of the bin
122 width. If *None*, automatically compute the width. Ignored
123 if *histtype* = 'step' or 'stepfilled'.
126 If *True*, the histogram axis will be set to a log scale.
127 If *log* is *True* and *x* is a 1D array, empty bins will
128 be filtered out and only the non-empty (*n*, *bins*,
129 *patches*) will be returned.
132 Color spec or sequence of color specs, one per
133 dataset. Default (*None*) uses the standard line
137 String, or sequence of strings to match multiple
138 datasets. Bar charts yield multiple patches per
139 dataset, but only the first gets the label, so
140 that the legend command will work as expected::
142 ax.hist(10+2*np.random.randn(1000), label='men')
143 ax.hist(12+3*np.random.randn(1000), label='women', alpha=0.5)
146 kwargs are used to update the properties of the
147 :class:`~matplotlib.patches.Patch` instances returned by *hist*:
153 .. plot:: mpl_examples/pylab_examples/histogram_demo.py
155 if not self._hold: self.cla()
162 if histtype
not in [
'bar',
'barstacked',
'step',
'stepfilled']:
163 raise ValueError(
"histtype %s is not recognized" % histtype)
165 if align
not in [
'left',
'mid',
'right']:
166 raise ValueError(
"align kwarg %s is not recognized" % align)
168 if orientation
not in [
'horizontal',
'vertical']:
170 "orientation kwarg %s is not recognized" % orientation)
173 if kwargs.get(
'width')
is not None:
174 raise DeprecationWarning(
175 'hist now uses the rwidth to give relative width '
176 'and not absolute width')
180 if isinstance(x, np.ndarray)
or not iterable(x[0]):
186 x = x.reshape(1, x.shape[0])
188 raise ValueError(
"x must be 1D or 2D")
189 if x.shape[1] < x.shape[0]:
190 warnings.warn(
'2D hist input should be nsamples x nvariables;\n '
191 'this looks transposed (shape is %d x %d)' % x.shape[::-1])
194 x = [np.array(xi)
for xi
in x]
199 color = [self._get_lines.color_cycle.next()
202 color = mcolors.colorConverter.to_rgba_array(color)
204 raise ValueError(
"color kwarg must have one color per dataset")
207 if weights
is not None:
208 if isinstance(weights, np.ndarray)
or not iterable(weights[0]) :
209 w = np.array(weights)
213 w.shape = (1, w.shape[0])
215 raise ValueError(
"weights must be 1D or 2D")
217 w = [np.array(wi)
for wi
in weights]
220 raise ValueError(
'weights should have the same shape as x')
222 if len(w[i]) != len(x[i]):
224 'weights should have the same shape as x')
232 _saved_autoscalex = self.get_autoscalex_on()
233 _saved_autoscaley = self.get_autoscaley_on()
234 self.set_autoscalex_on(
False)
235 self.set_autoscaley_on(
False)
238 _saved_bounds = self.dataLim.bounds
242 binsgiven = (cbook.iterable(bins)
or range !=
None)
251 xmin =
min(xmin, xi.min())
252 xmax =
max(xmax, xi.max())
258 hist_kwargs =
dict(range=range)
259 if np.__version__ <
"1.3":
260 hist_kwargs[
'new'] =
True
266 m, bins = np.histogram(x[i], bins, weights=w[i], **hist_kwargs)
269 m = (m.astype(float) / db) / m.sum()
271 if normed
and db.std() > 0.01 * db.mean():
273 This release fixes a normalization bug in the NumPy histogram
274 function prior to version 1.5, occuring with non-uniform
275 bin widths. The returned and plotted value is now a density:
277 where n is the bin count and N the total number of points.
284 if cbook.is_numlike(cumulative)
and cumulative < 0:
285 slc = slice(
None,
None,-1)
288 n = [(m * np.diff(bins))[slc].cumsum()[slc]
for m
in n]
290 n = [m[slc].cumsum()[slc]
for m
in n]
294 if histtype.startswith(
'bar'):
295 totwidth = np.diff(bins)
297 if rwidth
is not None:
298 dr =
min(1.0,
max(0.0, rwidth))
305 width = dr*totwidth/nx
309 boffset = -0.5*dr*totwidth*(1.0-1.0/nx)
313 elif histtype==
'barstacked':
315 boffset, dw = 0.0, 0.0
318 if align ==
'mid' or align ==
'edge':
319 boffset += 0.5*totwidth
320 elif align ==
'right':
323 if orientation ==
'horizontal':
328 for m, c
in zip(n, color):
329 patch = _barfunc(bins[:-1]+boffset, m, width, bottom,
330 align=
'center', log=log,
332 patches.append(patch)
339 elif histtype.startswith(
'step'):
340 x = np.zeros( 2*len(bins), np.float )
341 y = np.zeros( 2*len(bins), np.float )
343 x[0::2], x[1::2] = bins, bins
356 if align ==
'left' or align ==
'center':
357 x -= 0.5*(bins[1]-bins[0])
358 elif align ==
'right':
359 x += 0.5*(bins[1]-bins[0])
362 y[0],y[-1] = minimum, minimum
363 if orientation ==
'horizontal':
364 self.set_xscale(
'log')
366 self.set_yscale(
'log')
368 fill = (histtype ==
'stepfilled')
370 for m, c
in zip(n, color):
371 y[1:-1:2], y[2::2] = m, m
374 if orientation ==
'horizontal':
378 patches.append( self.fill(x, y,
379 closed=
False, facecolor=c) )
381 patches.append( self.fill(x, y,
382 closed=
False, edgecolor=c, fill=
False) )
385 if orientation ==
'horizontal':
386 xmin0 =
max(_saved_bounds[0]*0.9, minimum)
387 xmax = self.dataLim.intervalx[1]
389 xmin = np.amin(m[m!=0])
390 xmin =
max(xmin*0.9, minimum)
391 xmin =
min(xmin0, xmin)
392 self.dataLim.intervalx = (xmin, xmax)
393 elif orientation ==
'vertical':
394 ymin0 =
max(_saved_bounds[1]*0.9, minimum)
395 ymax = self.dataLim.intervaly[1]
397 ymin = np.amin(m[m!=0])
398 ymin =
max(ymin*0.9, minimum)
399 ymin =
min(ymin0, ymin)
400 self.dataLim.intervaly = (ymin, ymax)
403 labels = [
'_nolegend_']
410 'invalid label: must be string or sequence of strings')
412 labels += [
'_nolegend_'] * (nx - len(labels))
414 for (patch, lbl)
in zip(patches, labels):
421 if orientation ==
'vertical':
422 self.update_datalim([(bins[0],0), (bins[-1],0)], updatey=
False)
424 self.update_datalim([(0,bins[0]), (0,bins[-1])], updatex=
False)
426 self.set_autoscalex_on(_saved_autoscalex)
427 self.set_autoscaley_on(_saved_autoscaley)
428 self.autoscale_view()
431 return n[0], bins, cbook.silent_list(
'Patch', patches[0])
433 return n, bins, cbook.silent_list(
'Lists of Patches', patches)
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