필터 지우기
필터 지우기

How to color a range of bins in histogram?

조회 수: 16 (최근 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 CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by