multi bar labeling plot

조회 수: 107(최근 30일)
Ali Ali 2019년 5월 16일
편집: Adam Danz 2021년 12월 10일
I want to label each three bars as p1, p2 and p3 for all at the base as the pic attached.. i appreciate any help someone can provide.
댓글 수: 2표시숨기기 이전 댓글 수: 1
Ali Ali 2019년 5월 16일
you are right.. but i'll manopolate with the colors later.. so it will not be fixed as it now.

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

채택된 답변

편집: Adam Danz 2021년 12월 10일
Here's how to locate the center of each grouped bar and label them.
Starting in Matlab R2019B, the center of each bar is stored in
h = bar(___);
h.XEndPoints % x centers
h.YEndPoints % y endpoints
Prior to Matlab R2019B, you can use an undocumented property "XOffset". This was developed and tested in r2019a.
xCnt are the bar centers.
% Generate grouped bar plot
figure()
v = randi(20,12,3);
h = bar(v,.8);
% Get group centers
xCnt = get(h(1),'XData') + cell2mat(get(h,'XOffset')); % XOffset is undocumented!
% Create Tick Labels
xLab = repmat({'p1','p2','p3'},1,numel(xCnt)/3);
% Set individual ticks
set(gca, 'XTick', sort(xCnt(:)), 'XTickLabel', xLab)
Alternatively, you could rotate the x tick labels
set(gca, 'XTick', sort(xCnt(:)), 'XTickLabel', xLab, 'xticklabelrotation', 90)
% Or use xtickangle(): https://www.mathworks.com/help/matlab/ref/xtickangle.html
The best solution would be to use a legend
legend(h,{'p1','p2','p3'}) 댓글 수: 8표시숨기기 이전 댓글 수: 7
Ali Ali 2019년 5월 20일
thank you a lot Adam.. this is realy helped me.

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

추가 답변(2개)

Sulaymon Eshkabilov 2019년 5월 16일
Hi Ali,
Here is a simple solution to your problem:
A= randi([15, 25], 13, 3); % Insert your data here
H = bar(A); shg
H(1).FaceColor='g';
H(2).FaceColor='r';
H(3).FaceColor='b';
Good luck.
댓글 수: 1표시숨기기 없음
Ali Ali 2019년 5월 17일
Sulaymon Eshkabilov i think you did not get my point.. anyway thank you for your help.

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

Sergio Yanez-Pagans 2021년 8월 21일