How do I insert values into my bar plot (with 2 columns per x value)?

2 ビュー (過去 30 日間)
Chris
Chris 2013 年 1 月 29 日
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??

回答 (1 件)

Conrad
Conrad 2013 年 1 月 30 日
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

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by