Main Content

Box chart (box plot)

`boxchart(`

creates a box chart, or box
plot, for each column of the matrix `ydata`

)`ydata`

. If
`ydata`

is a vector, then `boxchart`

creates a
single box chart.

Each box chart displays the following information: the median, the lower and upper quartiles, any outliers (computed using the interquartile range), and the minimum and maximum values that are not outliers. For more information, see Box Chart (Box Plot).

`boxchart(`

groups the data in the vector `xgroupdata`

,`ydata`

)`ydata`

according to the unique values in
`xgroupdata`

and plots each group of data as a separate box chart.
`xgroupdata`

determines the position of each box chart along the
*x*-axis. `ydata`

must be a vector, and
`xgroupdata`

must have the same length as
`ydata`

.

`boxchart(___,'GroupByColor',`

uses color to differentiate between box charts. The software groups the data in the vector
`cgroupdata`

)`ydata`

according to the unique value combinations in
`xgroupdata`

(if specified) and `cgroupdata`

, and
plots each group of data as a separate box chart. The vector
`cgroupdata`

then determines the color of each box chart.
`ydata`

must be a vector, and `cgroupdata`

must
have the same length as `ydata`

. Specify the
`'GroupByColor'`

name-value pair argument after any of the input
argument combinations in the previous syntaxes.

`boxchart(___,`

specifies additional chart options using one or more name-value pair arguments. For
example, you can compare sample medians using notches by specifying
`Name,Value`

)`'Notch','on'`

. Specify the name-value pair arguments after all other
input arguments. For a list of properties, see BoxChart Properties.

returns
`b`

= boxchart(___)`BoxChart`

objects. If you do not specify
`cgroupdata`

, then `b`

contains one object. If you
do specify it, then `b`

contains a vector of objects, one for each
unique value in `cgroupdata`

. Use `b`

to set
properties of the box charts after creating them. For a list of properties, see BoxChart Properties.

You can add two types of data tips to a

`BoxChart`

object: one for each box chart and one for each outlier. A general data tip appears at the nonoutlier maximum value, regardless of where you click on the box chart.**Note**The displayed

`Num Points`

value includes`NaN`

values in the corresponding`ydata`

, but`boxchart`

discards the`NaN`

values before computing the box chart statistics.You can use the

`datatip`

function to add more data tips to a`BoxChart`

object, but the indexing of data tips differs from other charts.`boxchart`

first assigns indices to the box charts and then assigns indices to the outliers. For example, if a`BoxChart`

object`b`

displays two box charts and one outlier,`datatip(b,'DataIndex',3)`

creates a data tip at the outlier point.