Plot values of a boxplot next to it?

2 次查看(过去 30 天)
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!

采纳的回答

Chunru
Chunru 2022-7-14
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');

更多回答(0 个)

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by