Bar Plot of 2-D Array - How to label each individual bar with the value on top?
Mostrar comentarios más antiguos
So I've managed to get the value to show on the plot, but it is only over the middle plot. I would like to get the values to show up over their respective bars. I think I need to get the x-coordinates for each bar but am not quite sure about how to do that. Any help would be much appreciated. Here's my code:
x=[1:3]';
y=round(rand(3,5)*10);
bar(x,y)
[size_x,size_y]=size(y);
for i1=1:size_x
for j1=1:size_y
text(x(i1),y(i1,j1),num2str(y(i1,j1),'%0.2f'),...
'HorizontalAlignment','center',...
'VerticalAlignment','bottom')
end
end
Respuesta aceptada
Más respuestas (2)
sixwwwwww
el 28 de Oct. de 2013
Dear Robert, replace first two lines of your code as follows and you will get your desired bar plot:
x=[1:15]';
y=round(rand(15,1)*10);
I hope it helps. Good luck!
Image Analyst
el 29 de Oct. de 2013
0 votos
See my demo that does this, attached below.
2 comentarios
Image Analyst
el 29 de Oct. de 2013
Editada: Image Analyst
el 29 de Oct. de 2013
My intent was not to do exactly what you want to do but to show you, in a demo I already had on hand, how you could use text() to do what you wanted to do. You were supposed to modify my code or your code to use text() to do more exactly what you wanted, which it looks like you've done in the Answer you Accepted.
Categorías
Más información sobre Discrete Data Plots 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!