I want to change the 2D graph by changing the configuration of Boxplot.
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Jonas
le 20 Avr 2021
Modifié(e) : Jonas
le 20 Avr 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
Réponse acceptée
Jonas
le 21 Avr 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 commentaires
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Statistics and Machine Learning Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!