No 'CData' property on bar graph

조회 수: 15 (최근 30일)
Jack Olmstead
Jack Olmstead 2017년 10월 12일
답변: Roger Breton 2024년 1월 18일
I'm trying to make a bar graph and adjust the colors of individual bars. The most helpful online answers on how to do this involve using the 'CData' property of the bar object. However, in my particular bar graph, generated by the following code, there is no 'CData' property, and I'm confused as to why. Any help would be greatly appreciated!
eyesPlot = bar(1:4,eyesArray(:,2));
  댓글 수: 2
Steven Lord
Steven Lord 2017년 10월 12일
Which release are you using?
Jack Olmstead
Jack Olmstead 2017년 10월 12일
R2017a

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

답변 (2개)

Tom Holmes
Tom Holmes 2017년 11월 9일
This worked for me with 2017a release:
figure
BarMatrix = [your_matrix_here];
b = bar(BarMatrix,1,'LineStyle','none');
CData = lines(4);
for k = 1:size(BarMatrix,2)
b(k).FaceColor = CData(k,:);
end

Roger Breton
Roger Breton 2024년 1월 18일
Does not work for me?
I use:
data = [1 2 3 4];
figure
BarMatrix = [1 2 3 4];
b = bar(BarMatrix,1,'LineStyle','none');
CData = lines(4);
for k = 1:size(BarMatrix,2)
b(k).FaceColor = CData(k,:);
end
And all I get are four solid bars of blue?

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by