I cant plot values above the tips of bars, XEndPoints dos not work

조회 수: 5 (최근 30일)
Rahim Rahim
Rahim Rahim 2020년 12월 21일
댓글: Wondimu Bantihun 2022년 6월 20일
I am using Matlab 2018b, I want to plot values above the tips of bars, where:
A=[4, 8 , 20 ,5];
B=[1,3 4 ,8 ];y
I want to write strings above the bars, but when I use XEndPoints, the following message is shown :
No appropriate method, property, or field 'XEndPoints' for class 'matlab.graphics.chart.primitive.Bar'.
my code:
function DisplayBarTopsisSawRankReversal(A,B,...
X1,X2)
max1= max(A(1,:));
max2=max(B(1,:));
MAX=max(max1,max2);
% This will produce 4 groups of 3 different colored bars
x = [1 2 ];
y = [A;B];
Bar = bar(x,y); % h will have 3 handles, one for each color of bars
set(Bar, {'DisplayName'}, {'Txt1','Txt2'}');
legend() ;
somenames={X1,X2};
set(gca,'xticklabel',somenames);
ylabel('Rank Reversal Ratio [%]')
ylim([0 MAX+30]);
%text(xtips1,ytips1,string( ) ,'HorizontalAlignment','center','VerticalAlignment','bottom')
opts = {'VerticalAlign','middle', 'HorizontalAlign','left', ...
'FontSize',8, 'Rotation',90};
text(1, A(1) ,'s' , opts{:});
numel(Bar)
xtips2 = b(2).XEndPoints;
end
How can I add strings in my case ?

답변 (1개)

Star Strider
Star Strider 2020년 12월 21일
If you want to put the numbers on the tops of the bars, this works:
x = [1 2 ];
y = [A;B];
figure
Bar = bar(x,y); % h will have 3 handles, one for each color of bars % Return ‘bar’ Handle
% xtips1 = b(1).XEndPoints;
% ytips1 = b(1).YEndPoints;
for k1 = 1:size(A,2)
ctr(k1,:) = bsxfun(@plus, Bar(k1).XData, Bar(k1).XOffset'); % Note: ‘XOffset’ Is An Undocumented Feature, This Selects The ‘bar’ Centres
ydt(k1,:) = Bar(k1).YData; % Individual Bar Heights
end
for k1 = 1:size(ctr,2)
text(ctr(:,k1), ydt(:,k1), sprintfc('%d',ydt(:,k1)), 'HorizontalAlignment','center', 'VerticalAlignment','bottom')
end
I have no idea what you are doing otherwise, or the result you want.
Make appropriate changes to put whatever you want at the tops of the bars.
  댓글 수: 4
Star Strider
Star Strider 2020년 12월 21일
Rahim Rahim —
The easiest way is to use my code example to put what you want at the tops of the bars. (Use either the undocumented sprintfc or compose to create the appropriate strings.) I have no idea what you want to do with the rest of your code, since I do not understand what you are doing.
Wondimu Bantihun
Wondimu Bantihun 2022년 6월 20일
figure()
bargraph=[FND1,FND2,FND3,FND4,FND5;HND1,HND2,HND3,HND4,HND5;AND1,AND2,AND3,AND4,AND5];
X_as=categorical({'FND','HND','LND'});
bar(X_as,bargraph,'group');
how to put values on the top of the bar

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

카테고리

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

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by