Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2023.0.0 - Русский


plot a histogram


histplot(n, data [,normalization] [,polygon], <opt_args>)
histplot(x, data [,normalization] [,polygon], <opt_args>)
cf = histplot(..)



positive integer (number of classes)


increasing vector defining the classes (x may have at least 2 components)


vector (data to be analysed)


a boolean (%t (default value) or %f)


a boolean (%t or %f (default value))


This represents a sequence of statements key1=value1,key2=value2 ,... where key1, key2,... can be any optional plot2d parameter (style,strf,leg, rect,nax, logflag,frameflag, axesflag ).


Computed frequencies (bins heighs)


This function plots a histogram of the data vector using the classes x. When the number n of classes is provided instead of x, the classes are chosen equally spaced and x(1) = min(data) < x(2) = x(1) + dx < ... < x(n+1) = max(data) with dx = (x(n+1)-x(1))/n.

The classes are defined by C1 = [x(1), x(2)] and Ci = ( x(i), x(i+1)] for i >= 2. Noting Nmax the total number of data (Nmax = length(data)) and Ni the number of data components falling in Ci, the value of the histogram for x in Ci is equal to Ni/(Nmax (x(i+1)-x(i))) when normalization is true (default case) and else, simply equal to Ni. When normalization occurs the histogram verifies:


when x(1)<=min(data) and max(data) <= x(n+1)

Any plot2d (optional) parameter may be provided; for instance to plot a histogram with the color number 2 (blue if std colormap is used) and to restrict the plot inside the rectangle [-3,3]x[0,0.5], you may use histplot(n,data, style=2, rect=[-3,0,3,0.5]).

Frequency polygon is a line graph drawn by joining all the midpoints of the top of the bins of a histogram. Therefore we can use histplot function to plot a polygon frequency chart.

The optional argument polygon connects the midpoint of the top of each bar of a histogram with straight lines.

If polygon=%t we will have a histogram with frequency polygon chart.

Enter the command histplot() to see a demo.


Example #1: variations around a histogram of a gaussian random sample

d = rand(1,10000,'normal');  // the gaussian random sample

clf(); histplot(20,d);
clf(); histplot(20,d,normalization=%f);
clf(); histplot(20,d,leg='rand(1,10000,''normal'')',style=5);
clf(); histplot(20,d,leg='rand(1,10000,''normal'')',style=16, rect=[-3,0,3,0.5]);

Example #2: histogram of a binomial (B(6,0.5)) random sample

d = grand(1000,1,"bin", 6, 0.5);
c = linspace(-0.5,6.5,8);

histplot(c, d, style=2);
xtitle("Normalized histogram")

histplot(c, d, normalization=%f, style=5);
xtitle("Non normalized histogram")

Example #3: histogram of an exponential random sample

lambda = 2;
X = grand(100000,1,"exp", 1/lambda);
Xmax = max(X);

histplot(40, X, style=2);
x = linspace(0,max(Xmax),100)';
legend(["exponential random sample histogram" "exact density curve"]);

Example #4: the frequency polygon chart and the histogram of a gaussian random sample

n = 10;
data = rand(1,1000,"normal");

clf(); histplot(n, data, style=12, polygon=%t);
legend(["normalized histogram" "frequency polygon chart"],"lower_caption");

See also

  • histc — computes the histogram of a simple series of data
  • bar3d — 3D гистограмма
  • bar — bar histogram
  • plot2d — 2D plot
  • dsearch — поиск в упорядоченных наборах


5.5.0 polygon option and cf output added.
Report an issue
<< graypolarplot 2d_plot ВидЛинии >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Tue Mar 07 09:28:48 CET 2023