Editing the properties of box plot groups.
15 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Adam Danz
on 17 Dec 2020
Edited: Adam Danz
on 5 Jan 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))
More Answers (0)
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!