フィルターのクリア

How to color a range of bins in histogram?

5 ビュー (過去 30 日間)
Yan Liu
Yan Liu 2016 年 2 月 12 日
コメント済み: Roman 2020 年 2 月 21 日
Dear scholars,
I have created a simple histogram.
x = rand(10000,1); histogram(x);
I want to color the bins after 0.5 red but I do not know how to do that. Thank you so much for your help.
Pete

回答 (1 件)

Mike Garrity
Mike Garrity 2016 年 2 月 12 日
Usually the most robust way is to create two separate histogram objects:
x = rand(10000,1);
mask = x<.5;
bin_edges = 0:.1:1;
histogram(x(mask),bin_edges);
hold on
histogram(x(~mask),bin_edges,'FaceColor','red');
hold off
Then you can set any properties you like on each of the two objects.
  3 件のコメント
Image Analyst
Image Analyst 2016 年 2 月 12 日
Please go ahead and "Accept this answer" so we know it's solved.
Roman
Roman 2020 年 2 月 21 日
How can I do that, when I do not know the binedges in advance. I trid something like:
1.)
mask=cdw(:,2:j)>=100;
hx=histogram(a2,cdw(mask),'Orientation','horizontal','Normalization','probability','Parent',a2,'FaceColor','green');
hold on
hx=histogram(a2,cdw(~mask),'Orientation','horizontal','Normalization','probability','Parent',a2,'FaceColor','red');
hold off
2.)
mask=cdw(:,2:j)>=100;
hx=histogram(a2,cdw(mask),'Orientation','horizontal','Normalization','probability','Parent',a2,'FaceColor','green');
bin_Edges=hx.BinEdges;
hold on
hx=histogram(a2,cdw(~mask),'Orientation','horizontal','Normalization','probability','Parent',a2,'BinEdges',bin_Edges,'FaceColor','red');
hold off
But both do not work properly; around 100 I get an intersection part of bars where colors are on top of each other.
Thanks

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeHistograms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by