MATLAB: Display the data points to a boxplot

box plotloglog plotMATLABscatter plot

I have the following data points:
x=[1,1,1,1,1,1,1,1,1,1,1,1,24,24,24,24,24,24,24,24,24,24,24,24,24,72,72,72,72,72,72,72,72,72,72,72,72,72,120,120,120,120,120,120,120,120,120,120,120,120,120,168,168,168,168,168,168,168,168,168,168,168,168,168,360,360,360,360,360,360];
y1=[3.4,3.6,10.4,8.6,15.2,20,4.6,8.8,8.4,1.6,0.6,3.6,1.07,0.28,0.75,3.48,0.43,3.17,3.58,0.77,0.59,2.19,0.17,0.25,0.56,2,0.18,0.56,3.93,2.28,2.23,2.39,2.51,0.31,1.04,0.08,0.2,0.56,1.6,0.28,0.39,3.34,1.86,2.22,2.72,2.21,0.25,0.63,0.48,0.14,0.53,1.45,0.22,0.53,2.54,1.45,1.8,2.29,2.2,0.18,0.49,0.48,0.17,0.42,1.04,0.13,0.63,2.06,0.25,0.33];
C=[14.82,14.82,14.82,14.82,14.82,14.82,14.82,14.82,14.82,14.82,14.82,14.82,4.29,4.29,4.29,4.29,4.29,4.29,4.29,4.29,4.29,4.29,4.29,4.29,4.29,2.79,2.79,2.79,2.79,2.79,2.79,2.79,2.79,2.79,2.79,2.79,2.79,2.79,2.29,2.29,2.29,2.29,2.29,2.29,2.29,2.29,2.29,2.29,2.29,2.29];
I would like to plot loglog plot of x and C. and boxplot of x and y1. I need both in the same figure. Also I want to display the data ponts o boxplot to be display on boxplot to understant the distribution. My code is:
x=[1,1,1,1,1,1,1,1,1,1,1,1,24,24,24,24,24,24,24,24,24,24,24,24,24,72,72,72,72,72,72,72,72,72,72,72,72,72,120,120,120,120,120,120,120,120,120,120,120,120,120,168,168,168,168,168,168,168,168,168,168,168,168,168,360,360,360,360,360,360];
y1=[3.4,3.6,10.4,8.6,15.2,20,4.6,8.8,8.4,1.6,0.6,3.6,1.07,0.28,0.75,3.48,0.43,3.17,3.58,0.77,0.59,2.19,0.17,0.25,0.56,2,0.18,0.56,3.93,2.28,2.23,2.39,2.51,0.31,1.04,0.08,0.2,0.56,1.6,0.28,0.39,3.34,1.86,2.22,2.72,2.21,0.25,0.63,0.48,0.14,0.53,1.45,0.22,0.53,2.54,1.45,1.8,2.29,2.2,0.18,0.49,0.48,0.17,0.42,1.04,0.13,0.63,2.06,0.25,0.33];
C=[14.82,14.82,14.82,14.82,14.82,14.82,14.82,14.82,14.82,14.82,14.82,14.82,4.29,4.29,4.29,4.29,4.29,4.29,4.29,4.29,4.29,4.29,4.29,4.29,4.29,2.79,2.79,2.79,2.79,2.79,2.79,2.79,2.79,2.79,2.79,2.79,2.79,2.79,2.29,2.29,2.29,2.29,2.29,2.29,2.29,2.29,2.29,2.29,2.29,2.29,2.29,2,2,2,2,2,2,2,2,2,2,2,2,2,1.49,1.49,1.49,1.49,1.49,1.49];
loglog(x,C,'LineWidth',3,'Color','c')
hold on
plot(x,y1,'o')
hold on
boxplot(y1, x)
hold on
I got the following output.
I dont know why only the first boxplot points are showing. I have made a rough sketch of what the required figure is as follows.
Can anybody help me? I am stuck with this for the last two days.

Best Answer

The boxplot is not plotted against the correct x-values. The inserted x-array is treated as the grouping variable and the ticks are labelled accordingly, however the boxes are still plotted on x = [1 2 3 4...]. You can use the 'position' property to set the x-values.
figure;hold on
plot(x,y1,'o')
plot(x,C,'LineWidth',3,'Color','c')
boxplot(y1,x, 'positions',x)
set(gca,'xscale','log')
unfortunately the width of the boxes become inconsistent when setting the xscale to log.