How do I insert values into my bar plot (with 2 columns per x value)?
1 view (last 30 days)
Show older comments
If I have a vector A and matrix B and make a bar plot, how do I list the corresponding y values at the top of each bar? (I understand that you use the text() function but I cannot get it to work). An example of what I want to accomplish:
A = [1 2 3 4 5]; B = [4 7; 2 9; 3 7; 4 8; 1 3]; bar(A,B);
% how do I properly use text() or something else to insert the data values located in B??
0 Comments
Answers (1)
Conrad
on 30 Jan 2013
You can try something like this:
A = [1 2 3 4 5];
B = [4 7; 2 9; 3 7; 4 8; 1 3];
bar(A,B);
xOffsets = [-0.16 0.16];
yOffsets = [0.16 0.16];
for i = 1 : size(B,2)
text(A + xOffsets(i), B(:,i)' + yOffsets(i), num2str(B(:,i)));
end
Conrad
0 Comments
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!