Plotting multiple boxplots within the same plot/figure

I have six variables that I would like to plot within the same figure/plot as individual box-plots. I have tried doing so by plotting one, then using 'hold on' before the plotting the next, but this hasn't worked. How might I go about doing this?
Thank you.

2 个评论

I'm not quite sure how I would use subplot(). Below is essentially what I have tried.
boxplot(mat1, 'notch', 'on', 'colors','r') hold on
boxplot(mat2, 'notch', 'on','colors','b') hold on
And so on...

请先登录,再进行评论。

 采纳的回答

subplot(3,1,1)
boxplot(mat1, 'notch', 'on', 'colors', 'r')
subplot(3,1,2)
boxplot(mat2, 'notch', 'on', 'colors', 'b')
subplot(3,1,3)
boxplot(mat3, 'notch', 'on', 'colors', 'c')

1 个评论

I realize I wasn't being clear about what I needed to do.
I need them to be side-by-side boxplots.
Would you be able to help me with this instead?

请先登录,再进行评论。

更多回答(1 个)

This worked:
NMat= zeros (6, 10000); mat(:,:)=NaN;
mat(1,1:10000) = mat1; mat(2,1:10000) = mat2; mat(3,1:10000) = mat3;
mat(4,1:10000) = mat4; mat(5,1:10000) = mat5; mat(6,1:10000) = mat6;
NMat=mat; NMat=NMat'; boxplot(NMat, 'notch', 'on', 'colors', 'rb')

1 个评论

shortcut:
NMat = nan(6, 10000);
And since you are copying the same number of columns for each you can eliminate the other lines:
boxplot( [mat1(:), mat2(:), mat3(:), mat4(:), mat5(:), mat6(:)], 'notch', 'on', 'color', 'rb')

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by