Boxchartの色をそれぞれ変える方法
显示 更早的评论
3つの箱ひげ図を並べた状態で色をそれぞれ違う色にするにはどのようにすればよいでしょうか.
boxcolor = ["#4DBEEE", "#D95319", "#EDB120"];
data1 = rand(10,3);
figure;
hold on
for n = 1:3
b = boxchart(data1(:,n));
b.BoxFaceColor = boxcolor(n);
end
xticklabels({'A','B','C'})
この書き方だと3つの図が重なってしまいます.
↓の図の配置で色だけそれぞれ変えたいです.

回答(2 个)
1 个评论
Atsushi Ueno
2024-2-3
boxplot 関数を使うには Statistics and Machine Learning Toolbox 等の Toolbox が必要です。
boxchart 関数に色を設定する機能 ('GroupByColor') がありますが考え方が少し違ってて、定義されたグループ毎の要素の色を設定する機能となっています。
boxcolor = ["#4DBEEE", "#D95319", "#EDB120"];
data1 = rand(10,3);
xdata = ones(10,1);
figure;
hold on
for n = 1:3
b = boxchart(xdata*n, data1(:,n));
b.BoxFaceColor = boxcolor(n);
end
xticks([1 2 3]);
xticklabels({'A','B','C'});
类别
在 帮助中心 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
