Class Histogram
- Known Subclasses:
-
Histogram in one variable
The bin index and the number of points in a bin can be obtained by
indexing the histogram with the bin number. Application of len() yields
the number of bins. A histogram thus behaves like a sequence of bin index
- bin count pairs.
Here is an example on usage:
>>> nsamples = 1000
>>> from numpy import random
>>> data = random.normal(1.0, 0.5, nsamples)
>>> import Scientific.Statistics as S
>>> S.mean(data)
0.9607056871982641
>>> S.standardDeviation(data)
0.50251811830486681
>>> S.median(data)
0.94853870756924152
>>> S.skewness(data)
0.038940041870334556
>>> S.kurtosis(data)
2.865582791273765
>>>
>>> from Scientific.Statistics.Histogram import Histogram
>>> h = Histogram(data, 50)
>>> h.normalizeArea()
>>> h[3]
array([-0.45791018, 0.01553658])
>>> x = h.getBinIndices()
>>> y = h.getBinCounts()
>>>
>>>
>>>
>>> nsamples2 = nsamples*100
>>> data = random.normal(1.0, 0.5, nsamples2)
>>> h.addData(data)
>>> h.normalizeArea()
>>> x2 = h.getBinIndices()
>>> y2 = h.getBinCounts()
>>> plot (x,y) and (x2,y2):
>>> import Gnuplot
>>> g = Gnuplot.Gnuplot(persist=1)
>>> g.xlabel('sample value'); g.ylabel('probability')
>>> d1 = Gnuplot.Data(x, y, with='lines',
... title='%d samples' % nsamples)
>>> d2 = Gnuplot.Data(x2, y2, with='lines',
... title='%d samples' % nsamples2)
>>> g.plot(d1,d2)
|
__getitem__(self,
index)
Returns:
an array of shape (2,) containing the bin value and the bin count |
|
|
|
__getslice__(self,
first,
last) |
|
|
|
|
int
|
__len__(self)
Returns:
the number of bins |
|
|
|
addData(self,
data)
Add values to the originally supplied data sequence. |
|
|
|
getBinCounts(self)
Return an array of all the bin counts. |
|
|
|
getBinIndices(self)
Return an array of all the bin indices. |
|
|
|
normalize(self,
norm=1.0)
Scale all bin counts by the same factor |
|
|
|
normalizeArea(self,
norm=1.0)
Scale all bin counts by the same factor |
|
|
__getitem__(self,
index)
(Indexing operator)
|
|
- Parameters:
index (int ) - a bin index
- Returns:
- an array of shape (2,) containing the bin value and the bin count
|
__init__(self,
data,
nbins,
range=None)
(Constructor)
|
|
- Parameters:
data (Numeric.array of float or
int ) - a sequence of data points
nbins (int ) - the number of bins into which the data is to be sorted
range (tuple or NoneType ) - a tuple of two values, specifying the lower and the upper end of
the interval spanned by the bins. Any data point outside this
interval will be ignored. If no range is given, the smallest and
largest data values are used to define the interval.
|
__len__(self)
(Length operator)
|
|
- Returns:
int
- the number of bins
|
Add values to the originally supplied data sequence. Use this method
to feed long data sequences in multiple parts to avoid memory
shortages.
- Parameters:
data (Numeric.array ) - a sequence of data points
Note:
this does not affect the default range of the histogram, which is
fixed when the histogram is created.
|
normalize(self,
norm=1.0)
|
|
Scale all bin counts by the same factor
- Parameters:
norm (float or int ) - the sum of all bin counts after the rescaling
|
normalizeArea(self,
norm=1.0)
|
|
Scale all bin counts by the same factor
- Parameters:
norm (float or int ) - the area under the histogram after the rescaling
|