<< filledbounds Graphics identify >>

Stixbox >> Stixbox > Graphics > histo

histo

Plot a histogram

Calling Sequence

histo(x)
histo(x)
histo(x,n)
histo(...,Name,Value)
h=histo(...)
[h,edges]=histo(...)

Parameters

x :

a 1-by-p or p-by-1 matrix of doubles, the data

n :

a 1-by-1 matrix of doubles, the number of bins (default is Sturges rule : n = ceil(log2(p)+1), where p is the size of x. This is Sturges' rule.). If n is not a scalar, it contains the edges of the classes, in increasing order.

egdes :

a 1-by-(n+1) matrix of doubles, the edges of the classes of the histogram

h :

a 1-by-n matrix of doubles, h(i) is the number of values in x that belong to [edges(i), edges(i+1)[

Description

Compute and plots a histogram of the x.

Any input argument equal to the empty matrix is replaced by its default value.

[h,edges]=histo(...) computes the histogram without plotting.

Available options

Normalization: the kind of histogram we compute.

BinMethod: the method to compute the edges.

FaceColor: the color of the bars, as a string or a RGB row vector with 3 entries.

Compatibility notes

The advantage of the stixbox/histo function over the Scilab/histplot function is that the number of classes n can be automatically computed in histo, while it is the first argument of histplot.

Examples

x=distfun_chi2rnd(3,1000,1);
scf();
histo(x);
xtitle("Chi-Square random numbers","X","Frequency")

// Set the number of classes
scf();
histo(x,10);

// Set the edges
scf();
X=distfun_unifrnd(0,1,1000,1);
edges = 0:0.2:1.;
histo(X,edges);

// See with "count" Normalization
scf();
subplot(1,2,1)
histo(x,"Normalization","count");
// See with "pdf" Normalization
subplot(1,2,2)
histo(x,"Normalization","pdf");
x=linspace(0,15);
y=distfun_chi2pdf(x,3);
plot(x,y);

// See various colors and styles
scf();
subplot(1,3,1)
histo(x,"FaceColor","b");
subplot(1,3,2)
histo(x,"FaceColor","blue");
subplot(1,3,3)
histo(x,"FaceColor",[255,128,128]);

// Compute only histogram data
x=[0.4112  -0.2789  -0.23  0.0549  -1.0266];
[h,edges]=histo(x,4)

//
// Test BinMethod="integers"
scf();
pr=0.7;
N=10000;
R=distfun_geornd(pr,1,N);
histo(R,"BinMethod","integers","Normalization","pdf");
x=0:6;
y = distfun_geopdf(x,pr);
plot(x,y,"ro-")
legend(["N=1000","PDF"]);
xlabel("X")
ylabel("P")
title("Geometric Distribution pr=0.7")

//
// Compare Sturges vs Scott
data=distfun_normrnd(0,1,1000,1);
scf();
subplot(1,2,1)
histo(data,"BinMethod","scott","Normalization","pdf");
title("Scott''s rule")
subplot(1,2,2)
histo(data,"BinMethod","sturges","Normalization","pdf");
title("Sturges''s rule")

Authors


Report an issue
<< filledbounds Graphics identify >>