How can I change the location/size of whiskers and box in a BOXPLOT in Statistics Toolbox 7.0 (R2008b)?

39 views (last 30 days)
I want to change the extent of the 'box edges' from the default 25% and 75% percentile marks and the default  'whisker' extent calculation, respectively, to some other values in a BOXPLOT.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 19 Oct 2017
There is no way to specify the extent of the box edges in Statistics Toolbox 7.0 (R2008b). The default extents are 25% and 75% percentile.
The extent of 'whiskers' can be specified by using the 'whisker' property for BOXPLOT in terms of the 'whisker' length paramter 'w'.  This parameter is typically a factor by which the interquartile distance (distance between the extents of the 25th and 75th percentile marks) is multiplied to get the whisker extent. Currently there is no other way of specifying the whisker extent.
As a workaround, one can get a handle to the line objects that make up the boxplot and change their XData and YData properties appropriately. For example, you can attain the handle to the upper and lower whisker line objects and the upper and lower adjacent value line objects as follows.
samples = rand(100,1);
hAx = axes; % create axes object and handle
boxplot(samples) % draw a box plot
lines = hAx.Children; % get handles to the lines in the HGGroup object
uw = findobj(lines, 'tag', 'Upper Whisker'); % get handle to "Upper Whisker" line
uav = findobj(lines, 'tag', 'Upper Adjacent Value'); %get handle to "Upper Adjacent Value" line
lw = findobj(lines, 'tag', 'Lower Whisker'); % get handle to "Lower Whisker" line
lav = findobj(lines, 'tag', 'Lower Adjacent Value'); %get handle to "Lower Adjacent Value" line
The whiskers could be modified to, for example, the 5th and 95th percentile values using the "quantile" function.
uw.YData(1,2) = quantile(samples,0.95);
uav.YData(:) = quantile(samples,0.95);
lw.YData(1,1) = quantile(samples,0.05);
lav.YData(:) = quantile(samples,0.05);
 

More Answers (0)

Products


Release

R2016a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!