Boxplots in the same figure
6 ビュー (過去 30 日間)
古いコメントを表示
Hi everyone
How can I compaine two boxplots in the same figure for this code?
figure
sgtitle('main graph')
subplot(1,2,1);
boxplot(X,'first')
ylabel('timer')
grid on
subplot(1,2,2);
boxplot(Y,'Second')
ylabel('timer')
grid on
I've tried used solution in below link but still I have problem:
I've tried:
figure
hold on
x=[X;Y];
boxplot(x(1,:),'first')
boxplot(x(2,:),'secondl')
hold off
ylabel('timer')
title('main graph')
also I've tried this solution but still there are error
= [16 20 15 17 22 19 17]';
B = [22 15 16 16 16 18]';
C = [23 9 15 18 13 27 17 14 16 15 21 19 17]';
group = [ ones(size(A));
2 * ones(size(B));
3 * ones(size(C))];
figure
boxplot([A; B; C],group)
set(gca,'XTickLabel',{'A','B','C'})
4 件のコメント
Adam Danz
2022 年 2 月 11 日
Thanks, but it's still not clear. Let's say subplot A has 3 boxs and subplot B has 3 boxs. Do you want
[AB AB AB] or [ABABAB]
or
[AAA BBB] or [AAABBB]?
Adam Danz
2022 年 2 月 11 日
NOUF ALHARBI's answer moved here as a comment
----------------------------------------------------------------------
Subplot A has 1 box and subplot B has 1 box so just I want [A B]
but apeared to me like this:

採用された回答
Adam Danz
2022 年 2 月 11 日
Method 1: set position along x-axis
A = rand(10,1);
B = rand(8,1);
hold on
boxplot(A, 'Positions', 1)
boxplot(B, 'Positions', 2)
% Set desired xtick, xticklabels, and xlim
set(gca,'XTickMode','auto','XTickLabelMode','auto','XLimMode','auto')
Method 2: Combine columns of data
Vectors must have the same length. Pad shorter vectors with NaN values to equate lengths, if necessary.
A = rand(10,1);
B = rand(10,1);
data = [A(:),B(:)];
figure
boxplot(data)
4 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Fit Postprocessing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

