
HIST 関数で描画したヒストグラムの色や透明度を変更するにはどうすればよいですか?
14 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
1つの座標軸上に複数のヒストグラムを重ね合わせて描画しようと思います。その際、それぞれのヒストグラムの色や、透明度を変更したいのですが、HIST 関数では、出力引数としてハンドルを得られないため、現在では、以下のように FINDOBJ 関数を使用しています。
Y1 = randn(1,100);
hist(Y1);
h = findobj(gca,'Type','patch');
set(h,'FaceAlpha',0.2,'FaceColor','r')
Akzeptierte Antwort
MathWorks Support Team
am 23 Feb. 2010
HIST 関数の代わりに、BAR 関数を使用することで、ハンドルの取得が容易になり、ヒストグラムの色の変更や透明度の変更が可能です。
BAR 関数に入力するデータは、HIST 関数の出力引数である、各ビンの位置と、各ビンの個数です。
以下に例を示します。
Y1 = randn(1,100);
Y2 = 1.5*randn(1,100)-1;
% 各ビンにおける個数とその位置を取得
[n1,x1] = hist(Y1);
[n2,x2] = hist(Y2);
% ヒストグラムの描画
h1 = bar(x1,n1,'hist');
hold on
h2 = bar(x2,n2,'hist');
% 色や透明度の設定
set(h1,'FaceAlpha',0.2)
set(h2,'FaceAlpha',0.2,'FaceColor','r')

0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Histograms finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!