Reputation: 133
Using the answer to my previous question, I plotted the histogram for a cell array 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)
Displaying on the y axis the percentage of each xvalue occurrence, is it possible to show the percentages numbers on the histogram as I added in the image above so one can easily visualize the numbers?
Upvotes: 4
Views: 4305
Reputation: 3914
The text
function is IMHO the friendliest of the annotation objects because it accepts graph coordinates rather than normalized figure coordinates.
K = numel(centers);
for k = 1:K
text(centers(k),pcts(k),[num2str(pcts(k)) '%'],'HorizontalAlignment','center','VerticalAlignment','bottom')
end
This will put the percentage value at the top of each bar. Look at the help page for text
for further enhancements, like controlling the position, color, font, etc. of the placed text.
Upvotes: 4