Plotting a table with text inside
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
George
am 25 Jan. 2015
Kommentiert: Image Analyst
am 26 Jan. 2015
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 Kommentare
Akzeptierte Antwort
Geoff Hayes
am 25 Jan. 2015
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 Kommentare
Image Analyst
am 26 Jan. 2015
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');
Weitere Antworten (1)
Image Analyst
am 25 Jan. 2015
Use image() or imshow() instead of pcolor(). pcolor() chops off the last row and last column. Then use text() like Geoff shows.
1 Kommentar
Image Analyst
am 25 Jan. 2015
The application reminds me of the color frequency image: http://www.mathworks.com/matlabcentral/fileexchange/28164-color-frequency-image
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!