Editing the properties of box plot groups.
17 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Adam Danz
2020-12-17
编辑:Adam Danz
2021-1-5
> 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))
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!