Calculate histogram
histogram data nbins
(histogram data nbins min max norm)
Calculates histogram of data provided as a collection of values. Histogram is created with nbins
and optionally can have range fixed at lower or upper limit with min and max values (use "auto
as the value of min if only max is to be fixed). If norm is provided then histogram area is normalized to this value.
Histogram is an array of 4-element arrays, each corresponding to one bin in the histogram. Meanings of items in bin arrays are following:
bin mid-x-value; bin height; x-error (half of the bin width); y-error (square root of the number of entries in the bin, optionally
normalized).
POOL provides helper class plot_histo
and factory function make_histo
for creating histogram plots, both
available in make_plots.l
include file. See usage in the examples below.
Example 1:
"a := (rnorm 10 2 1000)
print (histogram :a 10 5 15)
Output:
{ {5.5 17 0.5 4.12310562561766}
{6.5 46 0.5 6.78232998312527}
{7.5 114 0.5 10.6770782520313}
{8.5 150 0.5 12.2474487139159}
{9.5 194 0.5 13.9283882771841}
{10.5 186 0.5 13.6381816969859}
{11.5 140 0.5 11.8321595661992}
{12.5 82 0.5 9.05538513813742}
{13.5 41 0.5 6.40312423743285}
{14.5 16 0.5 4} }
Example 2:
include "make_plots.l
"a := (rnorm 10 2 1000)
"h := (make_histo :a 10 5 15)
"cname := world @ :h
print :cname
setrange :cname {0 20} {}
(autoscale "Histogram "y)
"cfg := thing word :cname "_canvas_cfg
:cfg,"min_y := 0
wait 1000
(set_nbins 20) @ :h
Output:
histogram
Example 3:
include "make_plots.l
to bars :d :n :c [:min 0] [:max 10]
use (plot_histo :d :n :min :max 1)
:style,"xerr := "none
setti "bar
setr (:max - :min) / :n
(settc :c 20)
to resize :new_n
setr (:max - :min) / :new_n
set_nbins :new_n
end
end
"j := 5000
"k := 3
"h := []
repeat :k [
push :h (anewp "pool $bars (rnorm repcount repcount/2 :j) 100 100*repcount)
]
setrange "pool {0 10} {0 1}
"s := (slider "|n =| {70 4} {10 200 1} 100)
setonchange :s [(resize getvalue :s) @ :h]
ht
Output:
Histogram plots, the number of bins is changed with the slider.
See also:
Table of Content