Plotting a table with text inside
조회 수: 4 (최근 30일)
이전 댓글 표시
Hello
I am trying to plot a table with specific sizes, the resulted graph is either pcolor or contourf, but I require additional information to be shown in the field alongside with specified axis range and intervals.
the code I am using is of the form
xb = [3:1:13];
yb=[0.5:0.5:5.5];
data=[0,0,0,0,0,0,0,0,0,0,0;
0,49,73,85,86,83,78,82,67,63,59;
54,136,193,205,196,182,167,153,142,132,123;
106,265,347,347,322,294,265,244,224,207,193;
175,429,522,499,457,412,372,337,312,288,267;
262,600,600,600,600,540,484,442,399,367,340;
0,0,0,0,0,0,0,0,0,0,0;
0,0,0,0,0,0,0,0,0,0,0;
0,0,0,0,0,0,0,0,0,0,0;
0,0,0,0,0,0,0,0,0,0,0;
0,0,0,0,0,0,0,0,0,0,0;]
% analysis
bins=[11,11];
n =hist3(data,bins);
plotting
figure
pcolor(xb,yb,data),colorbar
I would like to replicate and insert the values as shown in figure 1 to the second figure.
Is there a way to import my data so as to be shown in the final figure as numbers on top of the color?
I found a very useful script in the exchange section although unfortunately it does not completely suits the figure output I want since it includes values that I wish not to be shown. but it may be useful to others http://uk.mathworks.com/matlabcentral/fileexchange/15877-heat-maps-with-text
thank you in advance
댓글 수: 0
채택된 답변
Geoff Hayes
2015년 1월 25일
George - a quick way to get text in (roughly) the centre of each square is to use the text function. Just append the following code to the end of your above code
% deltas for each x and y coordinate
dx = 1;
dy = 0.5;
% loop through each row of xb and yb
for k=1:size(xb,2)
for m=1:size(yb,2)
% add the value from data in roughly the centre of the square
text(xb(k)+ dx/2,yb(m)+dy/2,num2str(data(m,k)));
end
end
Running the above code will produce an image similar to what you have attached above (though it will be upside down). Try it and see what happens!
댓글 수: 2
Image Analyst
2015년 1월 26일
A short illustration:
m = magic(3); % Make a 3-by-3 array.
pcolor(m); % Attempt to display the 3-by-3 array.
title('Only 2 by 2 array shown instead of 3 by 3');
추가 답변 (1개)
Image Analyst
2015년 1월 25일
Use image() or imshow() instead of pcolor(). pcolor() chops off the last row and last column. Then use text() like Geoff shows.
댓글 수: 1
Image Analyst
2015년 1월 25일
The application reminds me of the color frequency image: http://www.mathworks.com/matlabcentral/fileexchange/28164-color-frequency-image
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!