The Histogram class constructs a histogram of data supplied using Tk widget classes. The XHistogram class also constructs a histogram, but then plots it using the 2D plotting system.
The most useful methods of both classes are summarized in below tables. The Histogram class counts the number of occurrences of data values that fall within each of a number of bins. Each bin represents a range of numbers. All bins have the same width, and the center of each bin will be an integer multiple of this width. Bin number 0 is always the one with the smallest center. Bins are added if new data arrives that does not fit within any of the existing bins. The getData method is used to read out the contents of a bin. If you start with bin number 0, and proceed until getData returns FALSE, you will have read all the bins.
Method |
Parameter |
Description |
---|---|---|
Histogram (...) |
|
constructor |
|
double width = 1.0 |
the width of each bin; bins are centered at integer multiples of this value |
|
int maxBins = 1000 |
since bins are added as needed, it is wise to limit their number |
void add (...) |
|
add a new sample to the histogram |
|
double x |
a data point for the historgram |
int numCounts () |
|
return the number of data values used so far in the histogram |
double mean () |
|
return the average value of all observed data so far |
double variance () |
|
return the variance of the observed data so far |
getData (...) |
|
get the count for a given bin; return FALSE if the bin is out of range |
|
int binno |
starting at 0, the bin number |
|
int& count |
place to store the count for the given bin |
|
double& binCenter |
place to store the center of the given bin |
Method |
Parameter |
Description |
---|---|---|
void initialize (...) |
|
start a new histogram |
|
Block* parent |
pointer to the block using the class |
|
double binWidth |
the width of each bin; bins are centered at integer multiples of this value |
|
const char* options |
options to pass to the 2D plotting system, in addition to -bar -nl -brw |
|
const char* title |
title to put on the histogram |
|
const char* saveFile |
name of a file to save data to (or 0 if none) |
|
int maxBins = 1000 |
limit the number of bins |
void addPoint (...) |
|
add a new sample to the histogram |
|
double y |
a data point for the histogram |
int numCounts () |
|
return the number of data values used so far in the histogram |
double mean () |
|
return the average value of all observed data so far |
double variance () |
|
return the variance of the observed data so far |
void terminate () |
|
plot the histogram using the 2D plotting system |