![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/337837/image.png)
Change the color of each group in boxplotGroup
83 ビュー (過去 30 日間)
古いコメントを表示
data = {rand(100,2), rand(100,2)+.2, rand(100,2)-.2};
boxplotGroup(data, 'PrimaryLabels', {'a' 'b' 'c'}, ...
'SecondaryLabels',{'Group1', 'Group2'}, 'GroupLabelType', 'Vertical')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/337813/image.png)
Now my question is: is it possible to have 2 separate colors for these two groups that I have here? Like first group box be blue and the second is red?
Is it possible to have both a in each group green; and have both b in each group yellow?
Thank you so much.
0 件のコメント
採用された回答
Adam Danz
2020 年 7 月 27 日
編集済み: Adam Danz
2021 年 12 月 2 日
"Is it possible to have both a in each group green; and have both b in each group yellow?"
Yes. Use the "colors" propery but include an extra color that will not appear to account for the gap which is actually a box plot of all NaN values that doesn't appear. Since you have 2 groups of 3 plots, set 4 different colors.
data = {rand(100,2), rand(20,2)*.8, rand(1000,2)*1.2};
boxplotGroup(data, 'Colors', lines(4)) % See image below
% Or
% data = {rand(100,2), rand(20,2)*.8, rand(1000,2)*1.2};
boxplotGroup(data, 'Colors', lines(4))
% or
boxplotGroup(data, 'Colors', 'rcmk') % string arrays also accepted
Alternatively, you can set the colors after creating the grouped box plot.
data = {rand(100,2), rand(20,2)*.8, rand(1000,2)*1.2};
h = boxplotGroup(data);
set(h.axis.Children(1).Children,'Color', 'r')
set(h.axis.Children(2).Children,'Color', 'k')
set(h.axis.Children(3).Children,'Color', 'g')
Image of first example
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/337837/image.png)
"is it possible to have 2 separate colors for these two groups that I have here?"
Not with this function. You might want to explore Matlab's boxplot function using the grouping variable and the ColorGroup property.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!