How to display percentage mark for each value on a histogram in matlab

Using the answer to my previous question , I built a histogram for an array of cells using:

   [nelements,centers]=hist(cellfun(@numel,S));
      numNeighbors = cellfun(@numel,S);
      [nelements,centers]=hist(numNeighbors,unique(numNeighbors))
      pcts = 100 * nelements / sum(nelements)
      figure
      bar(centers,pcts)

enter image description here

By displaying the percentage of each xvalue on the y axis, is it possible to show the percent numbers on the histogram, as I added in the image above, so that numbers can be easily visualized?

+4
source share
2 answers

The function textis IMHO the friendliest of the annotation objects, because it takes the coordinates of the graph, not the normalized coordinates of the shape.

K = numel(centers);
for k = 1:K
    text(centers(k),pcts(k),[num2str(pcts(k)) '%'],'HorizontalAlignment','center','VerticalAlignment','bottom')
end

. text , , , .. .

+4

enter image description here

0

All Articles