Plot values of a boxplot next to it?
2 views (last 30 days)
Show older comments
Hi,
i'm currently working with the matlab function boxplot and need a representation of the corresponding values next to the boxplots (see figure) for better clarity. Is there any possibility to implement this with boxplot? In my use case the number of boxplots changes depending on the user input, so a static positioning of the numbers is not possible.
Thanks in advance!
0 Comments
Accepted Answer
Chunru
on 14 Jul 2022
x1 = rand(5,1);
x2 = rand(10,1);
x3 = rand(15,1);
x = [x1; x2; x3];
g1 = repmat({'First'},5,1);
g2 = repmat({'Second'},10,1);
g3 = repmat({'Third'},15,1);
g = [g1; g2; g3];
boxplot(x,g)
qx1 = quantile(x1, [.25 .5 .75]);
qx2 = quantile(x2, [.25 .5 .75]);
qx3 = quantile(x3, [.25 .5 .75]);
hold on
text(1+.25+zeros(1,3), qx1, string(qx1), 'HorizontalAlignment', 'left');
text(2+.25+zeros(1,3), qx2, string(qx2), 'HorizontalAlignment', 'left');
text(3+.25+zeros(1,3), qx3, string(qx3), 'HorizontalAlignment', 'left');
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!