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

3 次查看(过去 30 天)
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 个评论
Jonas
Jonas 2021-4-20
编辑:Jonas 2021-4-20
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

请先登录,再进行评论。

采纳的回答

Jonas
Jonas 2021-4-21
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

更多回答(1 个)

inseong Hwang
inseong Hwang 2021-4-21
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.

Community Treasure Hunt

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

Start Hunting!

Translated by