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 CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by