Box plot
boxplot(X)
boxplot(X,G)
boxplot(axes,X,...)
boxplot(...,'Name
',value
)
boxplot(X)
produces a box plot of the data
in X
. If X
is a matrix, there
is one box per column; if X
is a vector, there
is just one box. On each box, the central mark is the median, the
edges of the box are the 25th and 75th percentiles, the whiskers extend
to the most extreme data points not considered outliers, and outliers
are plotted individually. For controlling how much the whiskers extend,
see the 'whiskers'
namevalue pair argument.
boxplot(X,G)
specifies one or more grouping
variables G
, producing a separate box for each
set of X
values sharing the same G
value
or values. Grouping variables must have one row per element of X
,
or one row per column of X
. Specify a single grouping
variable in G
using a vector, a character array,
a cell array of strings, or a vector categorical array; specify multiple
grouping variables in G
using a cell array of these
variable types, such as {G1 G2 G3}
, or by using
a matrix. If multiple grouping variables are used, they must all be
the same length. Groups that contain a NaN
value
or an empty string in a grouping variable are omitted, and are not
counted in the number of groups considered by other parameters.
By default, character and string grouping variables are sorted in the order they initially appear in the data, categorical grouping variables are sorted by the order of their levels, and numeric grouping variables are sorted in numeric order. To control the order of groups, do one of the following:
Use categorical variables in G
and
specify the order of their levels.
Use the 'grouporder'
parameter
described below.
Presort your data.
boxplot(axes,X,...)
creates the plot in
the axes with handle axes
.
boxplot(...,'
specifies
one or more optional parameter name/value pairs, as described in the
following table. Specify Name
',value
)Name
in single
quotes.
Name  Value  

'plotstyle' 
 
'boxstyle' 
 
'colorgroup'  One or more grouping variables, of the same type as permitted
for  
'colors'  Colors for boxes, specified as a single color (such as  
'datalim'  A twoelement vector containing lower and upper limits,
used by  
'extrememode' 
A dotted line marks the limit if any points are
outside it, and two gray lines mark the compression region if any
points are compressed. Values at +/–  
'factordirection' 
 
'fullfactors' 
 
'factorseparator'  Specifies which factors should have their values separated
by a grid line. The value may be  
'factorgap'  Specifies an extra gap to leave between boxes when the
corresponding grouping factor changes value, expressed as a percentage
of the width of the plot. For example, with  
'grouporder'  Order of groups for plotting, specified as a cell array
of strings. With multiple grouping variables, separate values within
each string with a comma. Using categorical arrays as grouping variables
is an easier way to control the order of the boxes. The default is  
'jitter'  Maximum distance d to displace outliers
along the factor axis by a uniform random amount, in order to make
duplicate points visible. A d of  
'labels'  A character array, cell array of strings, or numeric
vector of box labels. There may be one label per group or one label
per
 
'labelorientation' 
When the labels are on the y axis, both settings leave the labels horizontal.  
'labelverbosity' 
 
'medianstyle' 
 
'notch' 
Two medians are significantly different at the
5% significance level if their intervals do not overlap. Interval
endpoints are the extremes of the notches or the centers of the triangular
markers. The extremes correspond to q_{2} –
1.57(q_{3} – q_{1})/sqrt(n)
and q_{2} + 1.57(q_{3} – q_{1})/sqrt(n),
where q_{2} is the median (50th
percentile), q_{1} and q_{3} are
the 25th and 75th percentiles, respectively, and n is
the number of observations without any  
'orientation' 
 
'outliersize'  Size of the marker used for outliers, in points. The
default is  
'positions'  Box positions specified as a numeric vector with one
entry per group or  
'symbol'  Symbol and color to use for outliers, using the same
values as the  
'whisker'  Maximum whisker length w. The default
is a w of  
'widths'  A scalar or vector of box widths for when 
When the plotstyle
parameter takes the value 'compact'
,
the following default values for other parameters apply.
Parameter  Default
when plotstyle is 'compact' 

'boxstyle'  'filled' 
'factorseparator'  'auto' 
'factorgap'  'auto' 
'jitter'  0.5 
'labelorientation'  'inline' 
'labelverbosity'  'majorminor' 
'medianstyle'  'target' 
'outliersize'  4 
'symbol'  'o' 
You can see data values and group names using the data
cursor in the figure window. The cursor shows the original
values of any points affected by the datalim
parameter.
You can label the group to which an outlier belongs using the gname
function.
To modify graphics properties of a box plot component, use findobj
with the Tag
property
to find the component's handle. Tag
values for
box plot components depend on parameter settings, and are listed in
the table below.
Parameter Settings  Tag Values 

All settings 

When 

When 

When 

[1] McGill, R., J. W. Tukey, and W. A. Larsen. "Variations of Boxplots." The American Statistician. Vol. 32, No. 1, 1978, pp. 12–16.
[2] Velleman, P.F., and D.C. Hoaglin. Applications, Basics, and Computing of Exploratory Data Analysis. Pacific Grove, CA: Duxbury Press, 1981.
[3] Nelson, L. S. "Evaluating Overlapping Confidence Intervals." Journal of Quality Technology. Vol. 21, 1989, pp. 140–141.
[4] Langford, E. "Quartiles in Elementary Statistics", Journal of Statistics Education. Vol. 14, No. 3, 2006.