# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

# plot::Histogram2d

Histogram plots of data

MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

## Syntax

plot::Histogram2d(data, <a = amin .. amax>, options)

## Description

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 7 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 0, 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 = [a_1 .. b_1, a_2 .. b_2, dots] 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 ai < x ≤ bi. 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.

## Attributes

AttributePurposeDefault Value
AffectViewingBoxinfluence of objects on the ViewingBox of a sceneTRUE
AntiAliasedantialiased lines and points?TRUE
Areathe area of a histogram plot0
Cellsclasses of histogram plots[7]
CellsClosedinterpretation of the classes in histogram plotsRight
ClassesClosedinterpretation of the classes in histogram plots[Right]
Colorthe main colorRGB::GeraniumLake
Datathe (statistical) data to plot
DrawModeorientation of boxes and barsVertical
Filledfilled or transparent areas and surfacesTRUE
FillColorcolor of areas and surfacesRGB::GeraniumLake
FillPatterntype of area fillingSolid
Framesthe number of frames in an animation50
Legendmakes a legend entry
LegendTextshort explanatory text for legend
LegendEntryadd this object to the legend?FALSE
LineColorcolor of linesRGB::Black
LineWidthwidth of lines0.35
LineStylesolid, dashed or dotted lines?Solid
LinesVisiblevisibility of linesTRUE
Namethe name of a plot object (for browser and legend)
ParameterEndend value of the animation parameter
ParameterNamename of the animation parameter
ParameterBegininitial value of the animation parameter
ParameterRangerange of the animation parameter
PointSizethe size of points1.5
PointStylethe presentation style of pointsFilledCircles
TimeEndend time of the animation10.0
TimeBeginstart time of the animation0.0
TimeRangethe real time span of an animation0.0 .. 10.0
Titleobject title
TitleFontfont of object titles[" sans-serif ", 11]
TitlePositionposition of object titles
TitleAlignmenthorizontal alignment of titles w.r.t. their coordinatesCenter
TitlePositionXposition of object titles, x component
TitlePositionYposition of object titles, y component
VisiblevisibilityTRUE
VisibleAfterobject visible after this time value
VisibleBeforeobject visible until this time value
VisibleFromToobject visible during this time range
VisibleAfterEndobject visible after its animation time ended?TRUE
VisibleBeforeBeginobject visible before its animation time starts?TRUE

## Examples

### 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]

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:

## Parameters

 data The data to plot: A list of real values or expressions in the animation parameter a. data is equivalent to the attribute Data. a Animation parameter, specified as a = amin..amax, where amin is the initial parameter value, and amax is the final parameter value.