Create 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.

Box plots reduce data samples to a number of descriptive parameters. Box plots are very useful for a quick overview and comparison of discrete data samples. To create a box plot, use the plot::Boxplot function. For example, create a box plot for the data samples data1 and data2 that contain random floating-point numbers from the interval [0.0, 1.0) and the value 2 (the outlier):

data1 := [frandom() $ i = 1..10]:
data1 := append(data1, 2);
data2 := [frandom() $ i = 1..10]:
data2 := append(data2, 2);
p := plot::Boxplot(data1, data2):
plot(p)

This plot demonstrate the following features:

  • The tops and bottoms of each box are the 25th and 75th percentiles of the data samples, respectively. The distances between the tops and bottoms are the interquartile ranges.

  • The line in the middle of each box is the sample median. A median is not always in the center of the box. The median shows the sample obliquity (skewness) of the sample distribution.

  • The lines extending above and below each box are the whiskers. Whiskers extend from the ends of the interquartile ranges to the furthest observations within the maximum whisker length. The maximum whisker length is 3/2 of the height of the central box measured from the top or bottom of the box.

  • The data points that lay beyond the whisker lengths are the outliers. Outliers are values that are more than 3/2 times the interquartile range away from the top or bottom of the box.

The Notched option enables you to create a box plot with notches. Notches display the variability of the median between samples:

p := plot::Boxplot(data1, data2, Notched = TRUE):
plot(p)