The problem is in axes limits (xlim
and ylim
). Briefly your 1st boxplots exist but hidden out of axes.
When you plot the second boxplot, it set its own limits ignoring the 1st boxplot. In addition, boxplot by default sets position (y values for horizontal orientation) as 1:number_of_groups
, but label them according to your groups. So the ylim
will be [0.5 number_of_groups+0.5]
.
Since your x values are between 0 and 0.05, they are not visible.
As a solution set the limits manually considering this boxplot behavior:
x = rand(10,1)/20;
xg = randi(2,10,1)/40;
y = rand(10,1);
yg = randi(2,10,1)/2;
bv = boxplot(x,xg,'orientation','vertical');
xlim manual
hold on
bh = boxplot(y,yg,'orientation','horizontal');
hold off
xlim([0 2.5])
ylim([0 2.5])
When you set position
parameter it determines the values instead of 1:number_of_groups
. You can set them close to the range of x
.