how to boxplot on the same figure?
15 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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',{' '})
0 Commenti
Risposte (1)
Sean de Wolski
il 29 Dic 2017
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])
Vedere anche
Categorie
Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!