Editing the properties of box plot groups.
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Rt Ro
el 16 de Dic. de 2020
Hi everybody,
I have two groups of data and I added a divider between them using 'factorSeparator',1. I have some problems:
I don't know how I can change the color of separator from gray to black.
I would like to highlight the background of each group with different colors like the below picture.
Also I am wondering how I can hide the cap of whisckers in boxplot.
could you please help me to do it?
0 comentarios
Respuesta aceptada
Adam Danz
el 17 de Dic. de 2020
Editada: Adam Danz
el 5 de En. de 2021
> I don't know how I can change the color of separator from gray to black.
I wish boxplot returned graphics handles, but it doesn't. You have to get them the hard way, the undocumented way which is always susceptible to change.
Here's a demo
% Create boxplot
load carsmall
boxplot(MPG,Origin,'FactorSeparator',1)
% Get handles to the vertical ConstantLine objects
ax = gca();
bh = ax.Children.Children
% Change color to black
bh(end).Color = 'k';
> I would like to highlight the background of each group with different colors like the below picture.
Use patch or fill to create the colored regions and uistack to put the patches under the existing objects. Use The coordinates are defined by the same handles.
bh(end).XData
bh(end).YData
Note that each pair of factor separator coordinates are separated by NaN values. Use xlim() to get the starting and ending coordinates at the left and right edges of the plot.
> I am wondering how I can hide the cap of whisckers in boxplot.
Alternatively, here's how to get the handles to the caps and delete them.
% Continuing from above...
allTags = get(bh, 'tag');
isCap = contains(allTags,'Adjacent'); % contains() requires r2016b
delete(bh(isCap))
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!