Adding the mean to a horizontal box plot

Viewed 33

I wanted to add the mean of the Young's modulus to my box plot. It works perfectly fine with a vertical box plot, but I can’t get it to work with a horizontal box plot... It looks like MATLAB is doing something, but not displaying anything except the box plot.

I tried to fix the axis, but that doesn’t work either. It looks like whenever the box plot is rotated everything that worked before gets thrown away.

%Boxplot all tensile strength tests
figure(f1)

subplot(2,1,2)
hold on
xlabel('Youngs Modulus [MPa]') ;
ylabel('Samples:') ;

boxplot(E,k,'orientation','vertical') ;

plot(E_mean,'ok');

hold off
1 Answers
plot(E_mean)

is the same as

plot(1:length(E_mean), E_mean)

That is, you plot values as the y coordinate against their index as the x coordinate.

When making a horizontal box plot, the function switches the coordinates to plot. That is, it plots the index as the y coordinate, and the values as the x coordinate. Thus, you should do:

plot(E_mean, 1:length(E_mean))
Related