# `plot`::`Boxplot`

Statistical box plots

MuPAD® notebooks will be removed in a future release. 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::Boxplot(`L1, …`, <`a = amin .. amax`>, `options`)
plot::Boxplot(`[L1, …]`, <`a = amin .. amax`>, `options`)
plot::Boxplot(`A`, <`a = amin .. amax`>, `options`)
plot::Boxplot(`s`, <`c1, …`>, <`a = amin .. amax`>, `options`)
plot::Boxplot(`s`, <`[c1, …]`>, <`a = amin .. amax`>, `options`)
```

## Description

`plot::Boxplot(data)` creates a box plot of the given data.

`plot::Boxplot` creates a box plot of discrete data samples. Box plots reduce data samples to a number of descriptive parameters and are a useful means of comparing statistical data.

In particular, each data sample is represented as one box. A typical box consists of the following subparts:

• A “central box” representing the central 50% of the data. Its lower and upper boundary lines are at the 25%/75% quantile of the data. A central line indicates the median of the data.

• Two vertical lines extending from the central box indicating the remaining data outside the central box that are not regarded as outliers. These lines extend maximally to times the height of the central box but not past the range of the data.

• Outliers: these are points indicating the remaining data.

With the special attribute `Notched` = `TRUE`, the sides of the boxes can be notched, thus providing additional information on the data sample. The horizontal width of the notches may be set by the attribute `NotchWidth`.

The special attributes `BoxCenters` and `BoxWidths` allow to center the boxes at arbitrary positions along the horizontal axis and to set the horizontal width of the boxes, respectively.

The special attribute `Averaged` determines whether the quantile values are computed with or without the option `Averaged` (cf. `stats::empiricalQuantile`).

Specifying `DrawMode` = `Horizontal`, the boxes are rotated by 90 degrees.

The attribute `Colors` allows to specify the color of each box in a box plot. A common color for all boxes may be specified via `Color`.

## Attributes

AttributePurposeDefault Value
`AffectViewingBox`influence of objects on the `ViewingBox` of a scene`TRUE`
`AntiAliased`antialiased lines and points?`FALSE`
`Averaged`mode for computing quantile lines in box plots`TRUE`
`BoxWidths`widths of boxes in a box plot[`0.8`]
`BoxCenters`position of boxes in a box plot[`1`]
`Color`the main color
`Colors`list of colors to use[`RGB::Blue`, `RGB::Red`, `RGB::Green`, `RGB::MuPADGold`, `RGB::Orange`, `RGB::Cyan`, `RGB::Magenta`, `RGB::LimeGreen`, `RGB::CadmiumYellowLight`, `RGB::AlizarinCrimson`]
`Data`the (statistical) data to plot
`DrawMode`orientation of boxes and bars`Vertical`
`Filled`filled or transparent areas and surfaces`TRUE`
`FillPattern`type of area filling`DiagonalLines`
`Frames`the number of frames in an animation`50`
`Legend`makes a legend entry
`LegendText`short explanatory text for legend
`LegendEntry`add this object to the legend?`FALSE`
`LineWidth`width of lines`0.35`
`LineStyle`solid, dashed or dotted lines?`Solid`
`LinesVisible`visibility of lines`TRUE`
`Name`the name of a plot object (for browser and legend)
`Notched`notched boxes in box plots`FALSE`
`NotchWidth`width of notches in box plots`0.2`
`ParameterEnd`end value of the animation parameter
`ParameterName`name of the animation parameter
`ParameterBegin`initial value of the animation parameter
`ParameterRange`range of the animation parameter
`TimeEnd`end time of the animation`10.0`
`TimeBegin`start time of the animation`0.0`
`TimeRange`the real time span of an animation`0.0` .. `10.0`
`Title`object title
`TitleFont`font of object titles[`" sans-serif "`, `11`]
`TitlePosition`position of object titles
`TitleAlignment`horizontal alignment of titles w.r.t. their coordinates`Center`
`TitlePositionX`position of object titles, x component
`TitlePositionY`position of object titles, y component
`Visible`visibility`TRUE`
`VisibleAfter`object visible after this time value
`VisibleBefore`object visible until this time value
`VisibleFromTo`object visible during this time range
`VisibleAfterEnd`object visible after its animation time ended?`TRUE`
`VisibleBeforeBegin`object visible before its animation time starts?`TRUE`

## Examples

### Example 1

Just to show basic usage of `plot::Boxplot`, we plot some data samples chosen arbitrarily:

```data1 := [5, 10, 24, -4, 13]: data2 := [7, 9, -1, 4, 10, 8, 12, 10, 15]: b := plot::Boxplot(data1, data2): plot(b)```

We can modify the appearance of the box plot in various ways:

```b::Notched := TRUE: b::Colors := [RGB::Green, RGB::Black]: b::BoxCenters := [2, 3]: b::FillPattern := XCrossedLines:```
`plot(b)`

`delete b:`

### Example 2

It is possible to shift the whole plot in x-direction by providing a center for the first box via `BoxCenters`:

```A := matrix([[ 5, 6, 19], [10, 5, 45], [24, 2, 12], [-3, 18, -10], [-4, 0, - 4]]):```
```plot(plot::Boxplot(A, BoxCenters = [2], Notched = TRUE, FillPattern = Solid))```

`delete A:`

### Example 3

The primary use of `plot::Boxplot` is comparing data sets. We shall do this for data produced by the following random number generators:

```f := stats::normalRandom(1, 0.2): g := stats::uniformRandom(0, 2):```

Now, we create small samples and compare their boxes:

```data1 := [f() \$ k = 1..100]: // Red data2 := [f() \$ k = 1..100]: // Green data3 := [g() \$ k = 1..100]: // Blue plot(plot::Boxplot(data1, data2, data1, data3, data2, data3, Colors = [RGB::Red, RGB::Green, RGB::Red, RGB::Blue, RGB::Green, RGB::Blue], BoxCenters = [1, 2, 4, 5, 7, 8], Notched = TRUE))```

Comparing the central boxes, the blue data differ significantly from the red and the green data. The red and green boxes, however, are quite similar – as they should, given that the red and green data were produced by the same random generator `f`.

`delete f, g, data1, data2, data3:`

### Example 4

For symmetric input data, the images generated by `plot::Boxplot` are symmetric, too:

`plot(plot::Boxplot([\$0..10], [5+5*sin(PI*n/20) \$ n=-10..10], Notched))`

### Example 5

By default, the quantile lines of the boxes are computed with the option `Averaged` (see `stats::empiricalQuantile` for details). When using `Averaged` = `FALSE`, the quantiles are computed without this option:

```r := random(0..10): SEED := 123: data := [r() \$ k = 1..250]: plot(plot::Boxplot(data, Averaged = TRUE, BoxCenters = 0.5, Color = RGB::Blue, Notched), plot::Boxplot(data, Averaged = FALSE, BoxCenters = 1.5, Color = RGB::Red, Notched) ):```

`delete r, SEED, data:`

### Example 6

Box plots can be animated. We create two data samples and fuse them to a symbolic superposition:

```f1 := stats::normalRandom(0, 1): f2 := stats::normalRandom(4, 8): data0 := sort([f1() \$ k = 1..100]): data1 := sort([f2() \$ k = 1..100]): data01 := [(1 - a)*data0[i] + a*data1[i] \$ i = 1..100]:```

The box associated with the data sample `data01` changes from the box associated with `data0` to the box associated with `data1` as the animation parameter increases from a = 0 to a = 1:

`plot(plot::Boxplot(data0, data01, data1, a = 0..1))`

`delete f1, f2, data0, data1, data01:`

## Parameters

 `L1, …` Data samples: lists of numerical real values or arithmetical expressions of the animation parameter `a`. `L1`, … is equivalent to the attribute `Data`. `A` An array of domain type `DOM_ARRAY` or a matrix of category `Cat::Matrix` (e.g., of type `matrix` or `densematrix`) providing numerical real values or arithmetical expressions of the animation parameter `a`. The columns are regarded as separate data samples. Also a 1-dimensional array, regarded as a single data sample, is accepted. `A` is equivalent to the attribute `Data`. `s` A data collection of domain type `stats::sample`. The columns in `s` are regarded as separate data samples. `s` is equivalent to the attribute `Data`. `c1, …` Column indices into `s`: positive integers. These indices, if given, indicate that only the specified columns in `s` should be used as data samples. If no column indices are specified, all columns in `s` are used as data samples. `a` Animation parameter, specified as `a```` = amin..amax```, where `amin` is the initial parameter value, and `amax` is the final parameter value.