| Contents | Index |
plot::Histogram2d(data) plots a histogram showing the distribution of the data.
Call:
plot::Histogram2d(data, <a = amin .. amax>, Options)
Parameters:
|
data: |
the data to plot: A list of real values or expressions in the animation parameter a. |
Related Domains:
plot::Bars2d, plot::Boxplot, plot::Scatterplot
Related Functions:
plot, plot::copy, stats::frequency
Details:
plot::Histogram2d creates a histogram plot of the given data, showing the frequency distribution in a user-definable cell array.
By default, data is grouped into
classes of equal width. To increase the number of cells, but still have them be of equal width, set Cells = [n], as in example 1. For full control over the classes, set Cells to a list specifying the cells, as in example 2.
As long as the attribute Area is not changed from its default value of
, plot::Histogram2d displays the absolute number of data in a class as the height of the corresponding bar. With Area = a, a > 0, the whole plot will take area a, with each rectangle area proportional to the number of data points in its cell. Example 3 shows the difference in detail.
By default, cells (“classes”) given by the attribute Cells =
are interpreted as a collection of semi-open intervals
that are closed at the right boundary. A data item x is tallied into the i-th cell if it satisfies
. Use the option CellsClosed = Left or the equivalent ClassesClosed = Left to interpret the classes as the semi-open intervals
that are closed at the left boundary.
Example 1
To plot a histogram of a normally distributed process, we first create a generator of random numbers with this distribution:
X := stats::normalRandom(0, 1)
![]()
Next, we create a small number of “measurements”:
data := [X() $ i = 1..20]
![[-0.5297400457, -0.5694234147, -0.5161446272, -1.090814471, 1.782520584, 0.6370330472, 0.6902341601, 0.3399758858, 1.177699186, -0.5970692982, -1.386247581, -0.9783222199, -0.7891413081, 0.2090732178, 0.2186783746, -0.7392138209, 0.6496128588, 0.6258699055, 3.606896706, -0.3319378999]](PRIMITIV_Histogram_images/math7.png)
This data is ready to be put into plot::Histogram2d:
plot(plot::Histogram2d(data))

This plot, if nothing else, shows that 20 samples are very few. Let us repeat the process with more data:
data := [X() $ i = 1..300]:
plot(plot::Histogram2d(data))

On the other hand, this amount of data certainly justifies a finer classification:
plot(plot::Histogram2d(data, Cells = [15]))

Example 2
It is also possible to give the cells (classes) directly. To do so, you should give them as ranges or lists with two elements, as in the following example:
X := stats::normalRandom(0, 1):
data := [X() $ i = 1 .. 100]:
min(data), max(data)
![]()
h := plot::Histogram2d(data,
Cells = [-2.5..-1.5, -1.5..-1, -1..0,
0..1, 1..1.5, 1.5..2.5])
![]()
plot(h)

It is even possible to use -infinity and infinity as border values in the cells:
h::Cells := [-infinity..-2, -2..-1, -1..0,
0..1, 1..2, 2..infinity]:
plot(h)

Example 3
One potential problem with classes of non-equal width is that still the height of the bars corresponds to the number of data points in a class. To see why this may be a problem, consider data perfectly uniformly distributed:
data := [i/1000 $ i = 1..1000]:
Plotting a histogram of this data, we see only very small deviations from a rectangle, caused by the fact that 1000 and 7 are coprime:
plot(plot::Histogram2d(data))

However, plotting a histogram with uneven classes, the image looks very much different:
plot(plot::Histogram2d(data,
Cells = [0..1/2, 1/2..2/3, 2/3..3/4, 3/4..4/5, 4/5..1]))

To make not the height, but rather the area of a bar depend on the number of samples in a class, set Area to a positive value:
plot(plot::Histogram2d(data,
Cells = [0..1/2, 1/2..2/3, 2/3..3/4, 3/4..4/5, 4/5..1],
Area = 1))

Note that with Area = 1, a histogram plot is scaled accordingly to the probability density function of the variable displayed:
X := stats::normalRandom(0, 1):
data := [X() $ i = 1..1000]:
h := plot::Histogram2d(data, Cells = [15],
Area = 1, Color = RGB::Blue):
f := plot::Function2d(stats::normalPDF(0, 1),
x = -3..3, LineWidth = 1*unit::mm,
Color = RGB::Black):
plot(h, f)

delete X, data, h, f:

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |