TotalDepth.util.Histogram

Produces histograms.

Created on Nov 29, 2011

class TotalDepth.util.Histogram.Histogram(pre_load=None)

A histogram class.

__init__(pre_load=None)

Initialize self. See help(type(self)) for accurate signature.

add(x, count=1)

Increments the count of value x by count (default 1).

__getitem__(x)

Returns the current count of x.

strRep(width=75, chr='+', valTitle='', inclCount=False)

Returns a string representation of the histogram in ASCII.

width - The maximum width to use.

chr - The character to use in the plot.

valTitle - The title to use for values.

inclCount - Include the actual count for each value?

__weakref__

list of weak references to the object (if defined)

Testing

Tests are in test/TestHistogram.py

Running Tests

$ python3 test/testHistogram.py

Test Coverage

$ coverage run test/testHistogram.py
...
$ coverage report -m

Examples

from TotalDepth.util import Histogram

myH = Histogram.Histogram()
for x in range(1, 12):
    self._hist.add(x, x)
print(self._hist.strRep())
# Prints """ 1 | ++++++
 2 | +++++++++++++
 3 | +++++++++++++++++++
 4 | +++++++++++++++++++++++++
 5 | ++++++++++++++++++++++++++++++++
 6 | ++++++++++++++++++++++++++++++++++++++
 7 | +++++++++++++++++++++++++++++++++++++++++++++
 8 | +++++++++++++++++++++++++++++++++++++++++++++++++++
 9 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"""