
HIST 関数で描画したヒストグラムの色や透明度を変更するにはどうすればよいですか?
19 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
1つの座標軸上に複数のヒストグラムを重ね合わせて描画しようと思います。その際、それぞれのヒストグラムの色や、透明度を変更したいのですが、HIST 関数では、出力引数としてハンドルを得られないため、現在では、以下のように FINDOBJ 関数を使用しています。
Y1 = randn(1,100);
hist(Y1);
h = findobj(gca,'Type','patch');
set(h,'FaceAlpha',0.2,'FaceColor','r')
Réponse acceptée
MathWorks Support Team
le 23 Fév 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Histograms dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!