필터 지우기
필터 지우기

Plotting multiple boxplots within the same plot/figure

조회 수: 24 (최근 30일)
Emma
Emma 2012년 11월 30일
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
Walter Roberson
Walter Roberson 2012년 11월 30일
subplot() ?
Emma
Emma 2012년 11월 30일
편집: Emma 2012년 11월 30일
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...

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2012년 12월 1일
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
Emma
Emma 2012년 12월 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개)

Emma
Emma 2012년 12월 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
Walter Roberson
Walter Roberson 2012년 12월 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