Box plotのボックス内の色を変更する方法

x = normrnd(5,1,100,1);
y = normrnd(6,1,100,1);
X = [x,y];
boxplot(X,'ColorGroup',[ ]);
とすると,BOX内の色を添付した例のように変更したい場合どのように変更しますか.
ColorGroupをどのように変更するのでしょうか.
よろしくお願い申し上げます.

 채택된 답변

Akira Agata
Akira Agata 2020년 4월 8일

1 개 추천

R2020aでMATLABの基本関数に追加されたboxchartを使うのはいかがでしょうか?
たとえば以下のようにすると、Box内と外れ値のマーカー色をグレーに指定することができます。
figure
boxchart(x,'BoxFaceColor',[0.5 0.5 0.5],'MarkerColor',[0.5 0.5 0.5])

댓글 수: 1

KT
KT 2020년 4월 8일
ご回答ありがとうございます。
boxchartの方が簡便で分かりやすそうです.
MATLAB R2020aの導入も考慮したいと考えます.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Etsuo Maeda
Etsuo Maeda 2020년 4월 8일

1 개 추천

別解でPatchで頑張るという方法もあります
clear; close all; rng default;
x = normrnd(5, 1, 100, 1);
y = normrnd(6, 1, 100, 1);
boxplot([x, y], 'Color', [0 0 0], 'Symbol', 'o');
h = findobj(gca, 'Tag', 'Box');
% draw patch with color
for k = 1:length(h)
patch(get(h(k), 'XData'), get(h(k), 'YData'), [0.8 0.8 0.8], 'FaceAlpha', 0.8);
end
% send patch from front to back
ax = gca;
ax.Children = ax.Children([end 1:end-1]);
HTH

댓글 수: 3

KT
KT 2020년 4월 8일
回答ありがとうございます.
以下構文
% send patch from front to back
ax = gca;
ax.Children = ax.Children([end 1:end-1]);
の,ax.Children = ax.Children([end 1:end-1]); はどのような意味でしょうか.大変基礎的で申し訳ありません.
Etsuo Maeda
Etsuo Maeda 2020년 4월 9일
% send patch from front to back
ax = gca;
ax.Children
ax.Children = ax.Children([end 1:end-1]);
ax.Children
として、何がCommand Windowに表示されているのか確認してみてください。
KT
KT 2020년 4월 10일
ご回答ありがとうございました。

댓글을 달려면 로그인하십시오.

카테고리

제품

릴리스

R2018b

질문:

KT
2020년 4월 5일

댓글:

KT
2020년 4월 10일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!