Borrar filtros
Borrar filtros

Plotting multiple boxplots within the same plot/figure

24 visualizaciones (últimos 30 días)
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 comentarios
Emma
Emma el 30 de Nov. de 2012
Editada: Emma el 30 de Nov. de 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...

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 1 de Dic. de 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 comentario
Emma
Emma el 1 de Dic. de 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?

Iniciar sesión para comentar.

Más respuestas (1)

Emma
Emma el 1 de Dic. de 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 comentario
Walter Roberson
Walter Roberson el 1 de Dic. de 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')

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by