Boxchartの色をそれぞれ変える方法
Afficher commentaires plus anciens
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つの図が重なってしまいます.
↓の図の配置で色だけそれぞれ変えたいです.

Réponses (2)
1 commentaire
Atsushi Ueno
le 3 Fév 2024
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'});
Catégories
En savoir plus sur Annotations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
