How do I make a boxplot with double y-axis and 4 vectors?

Hello, I want to make a boxplot which has four boxes next to each other of which two should be scaled to the y-axis on the left and two to the y-axis on the right. I do manage to get two y-axes and the correct vectors are scaled to the right y-axis, but the two vectors that belong to the same y-axis are plotted on top of each other instead of next to each other. Does someone know how to resolve this? Thanks in advance!
figure
yyaxis left
boxplot([x1,x2],'Notch','on','Labels',{'Met autonomous','Met dredged'});
yyaxis right
boxplot([x3,x4],'Notch','on','Labels',{'WS autonomous','WS dredged'});

 Accepted Answer

Unfortunately, TMW didn't give the possibility of having x locations for boxplot other than ordinal position of the columns in the input arrays so you have to fudge--
x=randn(100,4);
figure
yyaxis left
boxplot([x(:,1:2) nan(100,2)])
yyaxis right
boxplot([nan(100,2) x(:,3:4)],'labels',{'A ','B ','C','D'})
yields
where the extra NaN are placeholders that aren't plotted.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!