How to change the appearance of the boxplot with a whiskers?

106 views (last 30 days)
Hello everyone. I have the following code:
A = [1.128 0.701 0.562 0.469 0.836 0.644 0.510 0.535 0.528 0.585]';
B = [0.630 0.630 1.079 0.635 0.983 0.875 0.747 0.811 0.878 0.943]';
group = [ ones(size(A)); 2 * ones(size(B))];
figure
boxplot([A; B],group)
set(gca,'XTickLabel',{'group A','group B'})
I want to change the appearance of the two boxplots as shown in the figure on the right:
  • change dashed line to continuous line
  • change the sign of outliers form "+" with a dot or "o"
How is it possible to fix the code?

Accepted Answer

Matt J
Matt J on 20 Mar 2022
A = [1.128 0.701 0.562 0.469 0.836 0.644 0.510 0.535 0.528 0.585]';
B = [0.630 0.630 1.079 0.635 0.983 0.875 0.747 0.811 0.878 0.943]';
group = [ ones(size(A)); 2 * ones(size(B))];
figure
boxplot([A; B],group)
set(gca,'XTickLabel',{'group A','group B'})
h=findobj('LineStyle','--'); set(h, 'LineStyle','-');
h=findobj('Marker','+'); set(h, 'Marker','o'); set(h,'MarkerFaceColor','r')
  2 Comments
Alberto Acri
Alberto Acri on 20 Mar 2022
thanks, that's exactly what I wanted!
Can you tell me how to fill each box with different colors? Using the 3 values of RGB.
Matt J
Matt J on 20 Mar 2022
For that you should probably check some of the other box plotting routines on the File Exchange. This is just one example which seems to offer that kind of control:

Sign in to comment.

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!