File Exchange

image thumbnail


version (2.77 KB) by Dennis
Flexible box plot creation (allows unequal sample sizes and displays sample size and outlier index)


Updated 25 Jan 2012

View License

This simple function allows you to create individual boxes in a box plot. The boxes do not have to be based on the same sample size, and to emphasize this fact the sample size n is displayed in the box's tick label. Outliers are identified in the plot by their indices. The function can also return these indices in a vector.

Cite As

Dennis (2020). singlebox (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (5)


Hi Andreas,

Thank you.
Is this what you are looking for?

h = figure('visible','off');
for i=1:5

Hope this helps.

Kind regards,


Excellent script.

One question: Is it possible to open the boxplots in the background (keep figures from popping up when running)?

I like the fact that the function shows (and returns) the indizes of the outliers.

Suggestions for improvements:
- adjustable whisker size (now hardcoded to the boxplot standard of 1.5 - at least this fact should be documented)
- better display of outlier indizes - in the current version, numbers overlap and or thus often unreadable


Hi Ruth,

Suppose we have two samples, s1 and s2, of unequal size n1 and n2, respectively. That is, s1 is 1-by-n1 or n1-by-1 and similar for s2.
Then you could simply do the following:


The function automatically adds the second box to the current axes. You could also pass in a handle to an axes system if necessary.

Hope this helps.


p.s. Note that Matlab's own boxplot-function can also handle unequal sample sizes: Just insert NaN for "missing" values.


Can you give an example of how to implement your function with samples of different sizes?

MATLAB Release Compatibility
Created with R2009b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags