A number of people have asked me whether MATLAB can add text to heatmaps to show the exact values. This is very easy to do, however, making a the text robust to resizing, zooming and other operations is a little trickier.
This example shows how to add text to the heatmap and also includes an M-file that shows how to handle zooming and resizing.
Robert Henson (2021). Heat Maps with Text (https://www.mathworks.com/matlabcentral/fileexchange/15877-heat-maps-with-text), MATLAB Central File Exchange. Retrieved .
is there a way to change the pixel size?
The default seems to be that the pixels are rectangular, but I want them to be square.
Thanks in advance
Great function. Line 88 could be changed to something like:
textHandles(j,i) = text(j,i,sprintf(['%.' num2str(precision) 'f'],data(i,j)),...
Then the numeric precision is counting from the decimal point
Is there a way to make this function robust to a change of figure units to centimeters?
PS. to be able to use XtickLabel etc to name the axis after making this image, type "axis on"
Useful, instructive, and nicely presented.
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!