필터 지우기
필터 지우기

How do I get the FaceColor of a histogram if set to ‘auto’?

조회 수: 3 (최근 30일)
Gero Nootz
Gero Nootz 2015년 6월 1일
댓글: Walter Roberson 2015년 6월 2일
h1 = histogram(data); get(h1, 'FaceColor');
Returns ‘auto’ and not the set color.

채택된 답변

Cindy Solomon
Cindy Solomon 2015년 6월 2일
Hi Gero,
The actual FaceColor is based on the 'ColorOrder' property of the axes, so if you assumed that the color order hasn't been changed and that the histogram was the first thing plotted on that axes, you could query the color from that. Histograms follow the same model as plot, wherein the first item plotted uses the first color on the ColorOrder, the second item uses the second color, etc. For example, if you knew that the histogram was the first item plotted, you could do something like:
colorList = get(gca,'ColorOrder');
histColor = colorList(1,:);
Could you please clarify why you would need to get the color this way? I work at MathWorks and would like to better understand your use-case so that I can pass your feedback to the developers.
Hope this helps!
  댓글 수: 2
Gero Nootz
Gero Nootz 2015년 6월 2일
편집: Walter Roberson 2015년 6월 2일
Thanks Cindy,
I’m plotting more than one histogram on the same axis and later plot other things like lines and text which I would like to match in color to the histograms to which they belong.
Something like:
h2 = histogram(data)
plot(X, Y,'Color',h2.FaceColor)
text(,'Color',h2.FaceColor)
This works nicely if I specify the color like so:
h2 = histogram(data,'FaceColor',[0.851 0.325 0.098])
plot(X, Y,'Color',h2.FaceColor2)
but does not work in the previous case.
Walter Roberson
Walter Roberson 2015년 6월 2일
Cindy, is the implication that if you change order of Children in the axes, that the histogram might change color?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Labels and Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by