Plotting multiple boxplots within the same plot/figure

37 views (last 30 days)
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 Comments
Emma
Emma on 30 Nov 2012
Edited: Emma on 30 Nov 2012
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...

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 1 Dec 2012
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 Comment
Emma
Emma on 1 Dec 2012
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?

Sign in to comment.

More Answers (1)

Emma
Emma on 1 Dec 2012
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 Comment
Walter Roberson
Walter Roberson on 1 Dec 2012
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')

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!