Clear Filters
Clear Filters

how to use code for printing values on top of vertical bars with horizontal bars?

1 view (last 30 days)
Hello,
I want to try horizontal bars and print the values right of the bars.
My actual code which prints the values on top of each bar is the following ....
% Find the x location of each bar
xvals = unique(cell2mat(get(findall(hb,'type','patch'),'xdata')));
xvals = mean(reshape(xvals,2,[]));
% Put the text there
text(xvals,[DataFps1 DataFps2 DataFps3 DataFps4 DataFps5], ...
{[DataFpsLabels1 DataFpsLabels2 DataFpsLabels3 DataFpsLabels4 DataFpsLabels5]},...
'Vert','bot','horiz','cen','FontName','Arial','Fontsize',8);
My problem is that unfortunately I don't understand this code, which means I cannot alter it correctly. I have this code from another question which I asked on this forum. When I use "hbar"for horizontal bars, the values which you can see on top of the bars disapper.
How the code has to be altered?
Thanks, David

Answers (1)

Image Analyst
Image Analyst on 4 Feb 2013
They're the x and y values. In text, try adding an offset to the x values and reducing the y values by some factor, say half:
xvals+10,[DataFps1 DataFps2 DataFps3 DataFps4 DataFps5]* 0.5
  1 Comment
David
David on 4 Feb 2013
I tried but it won't work. It gives me an error:
Error using text
X and Y must be the same length
it seems when using barh instead of bar the xvals variable only contains 13 elements and not 25 as before.
It seems that something in these two lines is not working:
xvals = unique(cell2mat(get(findall(hb,'type','patch'),'xdata')));
xvals = mean(reshape(xvals,2,[]));

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!