Reduce the distance between boxplots

Dear all,
Here are my boxplots that generated from the below script:
figure();
ax = axes();
hold(ax);
for i=1:numel(data)
boxchart(x(i)*ones(size(data{i})), data{i},'MarkerStyle','none', ...
'BoxFaceColor', colors(i,:), ...
'LineWidth', 1, ...
'WhiskerLineStyle', '-','BoxWidth',0.5)
end
set(gca,'xtick',[1.5 3.5 5.5 7.5 9.5 11.5 13.5 15.5 17.5])
I want to reduce the distance between first and second boxes; as well as third and forth; ... and 15th and 16th.
In order to have 8 couple boxe beside each other. (each couple have distance with next couple)
please let me know how I can do that. Thanks

3 comentarios

dpb
dpb el 27 de Jul. de 2020
boxplot has no concept of an x-position and is built from a whole bunch of smaller line pieces. Theoretically one could go handle-diving and retrieve the coordinates of all the lines and mung on the X values judiciously, but would take quite a bit of forensics to get there.
It might be possible to create multiple axes for each group more simply where there's some room left between one axis and the next instead.
BN
BN el 27 de Jul. de 2020
Oh thank you
dpb
dpb el 27 de Jul. de 2020
Just noticed you're using the new boxchart; I don't have R2020a so have only boxplot
From the documenatation, doesn't appear the implementation is any different, fundamentally; the x-grouping input variable isn't a position but a group; positions are still ordinal.
But, did get a brainstorm...put a column of NaN in between each group of two; it will be non-showing but will still take up room so there will be a gap for the missing "variable".

Iniciar sesión para comentar.

 Respuesta aceptada

dpb
dpb el 27 de Jul. de 2020
Editada: dpb el 28 de Jul. de 2020
Carrying on from the above idea...
data=rand(10,16); % just some random data w/ 16 variables/columns
data2=[];
for i=1:8 % augment nan before/between each pair of two
data2=[data2 nan(10,1) data(:,2*i-1:2*i)];
end
data2=[data2 nan(10,1)]; % add the trailing nan column for balance
boxplot(data2) % and present the boxplot
xticks(2.5:3:26) % matchup ticks
ends up with--
which isn't too bad if say so meself! :)
Dunno what will happen/need to do to use barchart in order to get the coloring, too.

4 comentarios

BN
BN el 28 de Jul. de 2020
Thank you so much... amazing idea.
dpb
dpb el 28 de Jul. de 2020
NaN values have many uses for creating customized effects in handle graphics...indispensible "trick of the trade".
dpb
dpb el 28 de Jul. de 2020
BTW, I did try the multiple axes idea--
for i=1:8
hAx(i)=subplot(1,8,i);
boxplot(data(:,2*i-1:2*i))
xticks([]);
yticks([]);
end
wasn't too bad a first cut but would take more cleanup to label and all...the hidden variable trick seems the best option.
BN
BN el 29 de Jul. de 2020
Yes thank you again.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Distribution Plots en Centro de ayuda y File Exchange.

Productos

Versión

R2020a

Etiquetas

Preguntada:

BN
el 27 de Jul. de 2020

Comentada:

BN
el 29 de Jul. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by