MATLAB Answers

# I want to change the 2D graph by changing the configuration of Boxplot.

1 view (last 30 days)
inseong Hwang on 20 Apr 2021
Answered: Jonas on 21 Apr 2021
Hello.
Using Matlab's Boxplot function, a box graph with values of Max, Min, 25%, Median, and 75% is drawn.
I would like to change this to a box graph consisting of Max, Min, Mean-Standard Deviation, Mean, and Mean + Standard Deviation.
##### 1 CommentShowHide None
Jonas on 20 Apr 2021
you can try to change the values inside the boxplot function. open the function using
edit boxplot
and search for quantiles, i think they were named q25 or similarly. good luck, boxplot is a really ugly function to change. it would be easier if you just want to add the information you asked for

Sign in to comment.

### Accepted Answer

Jonas on 21 Apr 2021
so here the way i went so far: i change just the properties of the image, at the moment the code changes the median line to mean and the boxes to mean+std and mean-std. at the moment it leaves the whiskers (lines to min or max) unchanged, you should change it accordingly: i give you an example, you should be able to change it according to your wishes
clear
close all;
rng('default');
% generate some data
nrOfBoxes=4;
a=randi(5,9,nrOfBoxes);
boxplot(a);
% get lines from axis
bxpltAx=gca;
lines=bxpltAx.Children.Children;
% In the boxplot objects the objects are ordered for boxes from right to left
lines=flip(lines);
% make clear which line object is which (did not test all of them)
upperWhiskers=lines(1:nrOfBoxes);
lowerWhiskers=lines((1:nrOfBoxes)+1*nrOfBoxes);
maximums=lines((1:nrOfBoxes)+2*nrOfBoxes);
minimums=lines((1:nrOfBoxes)+3*nrOfBoxes);
boxes=lines((1:nrOfBoxes)+4*nrOfBoxes); % Corner YData and XData: left bot, left top, right top, right bot; pairwise line coordinates!
medians=lines((1:nrOfBoxes)+5*nrOfBoxes);
outliers=lines((1:nrOfBoxes)+6*nrOfBoxes);
% data you asked for calculated column-wise
means=mean(a);
stds=std(a);
for boxNr=1:nrOfBoxes
% set medians to means
medians(boxNr).YData=[means(boxNr) means(boxNr)];
% calculate new bounds
newUpperBound=means(boxNr)+stds(boxNr);
newLowerBound=means(boxNr)-stds(boxNr);
% set box bounds to mean+std and mean-std
boxes(boxNr).YData([2 3])=newUpperBound;
boxes(boxNr).YData([1 4 5])=newLowerBound;
end
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### More Answers (1)

inseong Hwang on 21 Apr 2021
Thank you.
Boxplot conversion is too difficult for me as I am immature with function changes.
Could you help me a little more?
p25 = means-standard deviation
p50 = mean
p75 = mean + standard deviation
I want to change p75 to Mean + standard deviation.
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Community Treasure Hunt

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

Start Hunting!