Y data on the bar plot
Mostrar comentarios más antiguos
I am using Bar plot for plotting the following code i am using
ABC=xlsread('ABC.xlsx');
figure(1);
for i= 0:3
A= bar(ABC(:,i+1:i+3))
set(gca,'XTicklabel',{'25','50','75','100'})
xlabel('time')
for j=1:3
text(A(i),sprintf('(%.0f)',A(i)))
end
end
But I want the y data on it how can i proceed any hint i am using text command...Any changes in code can anyone suggest Thank you in advance ..Also i am using Matlab 2016b version
Respuesta aceptada
Más respuestas (2)
n = 5 ;
x = (1:n) ;
y = randi(n,n,1) ;
bar(x,y)
hold on
text(x,y+0.1,num2str(y))
ylim([0 6])
1 comentario
Prasad Joshi
el 19 de En. de 2022
Simon Chan
el 19 de En. de 2022
Editada: Simon Chan
el 19 de En. de 2022
Why not using the example in the documentation by getting the EndPoints as follows:
clear;
clc;
x = [25 50 75];
vals = [6000 3000 3100;7000 3100 3200;7900 3100 3200];
b = bar(x,vals);
dx = [-5, 0 , 5];
text(cat(2,b.XEndPoints),cat(2,b.YEndPoints),string(cat(2,b.YData)),'HorizontalAlignment','center',...
'VerticalAlignment','bottom')
2 comentarios
Ankit
el 19 de En. de 2022
@Simon Chan: 'XEndPoints' property is available from 2019b version I think. And he is using 2016b.
Prasad Joshi
el 19 de En. de 2022
Categorías
Más información sobre Graphics Performance en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

