フィルターのクリア

how to boxplot on the same figure?

15 ビュー (過去 30 日間)
Hydro
Hydro 2017 年 12 月 29 日
コメント済み: Hydro 2017 年 12 月 29 日
Hello, I am trying to boxplot four data types on the same graph such that A and B remains on the left side, while C & D on the right side of the graph. I want to compare A to B and C to D. Elow is my code but i lose AB plot when i execute plotting for CD. Will highly appreciate if someone can help.
X1= [1.2 2.2 3.2 4.2 5.2];
X2=[1.4 2.4 3.4 4.4 5.4];
X3=[6.2 7.2 8.2 9.2 10.2];
X4=[6.4 7.4 8.4 9.4 10.4];
A=rand(100,10); % Data
B=rand(100,10)+5; % Data
f=figure;
hold on
BoxA = boxplot(A(:,1:5),'positions',X1, 'width',0.18,'notch','on','color','r');
set(gca,'XTickLabel',{' '})
BoxB = boxplot(A(:,6:10),'positions',X2, 'width',0.18,'notch','on','color','b');
set(gca,'XTickLabel',{' '})
BoxC = boxplot(B(:,1:5),'positions',X3, 'width',0.18,'notch','on','color','r');
set(gca,'XTickLabel',{' '})
BoxD = boxplot(B(:,6:10),'positions',X4, 'width',0.18,'notch','on','color','b');
set(gca,'XTickLabel',{' '})

回答 (1 件)

Sean de Wolski
Sean de Wolski 2017 年 12 月 29 日
Your xlimits are only showing one of the box plots. I'd also recommend using yyaxis here or perhaps subplots.
X1= [1.2 2.2 3.2 4.2 5.2];
X2=[1.4 2.4 3.4 4.4 5.4];
X3=[6.2 7.2 8.2 9.2 10.2];
X4=[6.4 7.4 8.4 9.4 10.4];
A=rand(100,10); % Data
B=rand(100,10)+5; % Data
f=figure;
yyaxis left
hold on
BoxA = boxplot(A(:,1:5),'positions',X1, 'width',0.18,'notch','on','color','r');
set(gca,'XTickLabel',{' '})
BoxB = boxplot(A(:,6:10),'positions',X2, 'width',0.18,'notch','on','color','b');
set(gca,'XTickLabel',{' '})
yyaxis right
BoxC = boxplot(B(:,1:5),'positions',X3, 'width',0.18,'notch','on','color','r');
set(gca,'XTickLabel',{' '})
BoxD = boxplot(B(:,6:10),'positions',X4, 'width',0.18,'notch','on','color','b');
set(gca,'XTickLabel',{' '})
xlim([0 12])
  1 件のコメント
Hydro
Hydro 2017 年 12 月 29 日
Thank you Sean, Is there a way to match the color the outliers as like their boxes. right now it is showing al red. Also, I see tickmark on x-axis on the right graph.

サインインしてコメントする。

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by