1
votes

I have a bar graph in which i would like to plot data labels alongside my data points. I have looked at this documentation and they don't seem to have what i need. This is all done using MATLAB.

Below is an example of what i'd like, although for a bar graph instead of a scatter plot.

enter image description here

2
What's wrong with the text() function described in that link? - Danica
I used it, but it does not display in the graph. Note that, this is a subplot graph of two different graphs. - Jeiman

2 Answers

1
votes

Use TEXT function to label the bars. STRCAT function can be used to create custom labels.

x = (1:5)';
y = rand(5,1);
bar(x,y)
%# show X and Y coordinates
text(x,y,strcat('(',num2str(x),',',num2str(y,2),')'),...
     'horiz','center','vert','bottom')

You can also add some small gap to y coordinates to make text a little higher.

0
votes

Use the code below and customize in your case.

for ii = 1:numel(X) 
        text(X(ii)+.02, Y(ii)+.02,textCell{ii},'FontSize',8) 
    end