Highlight specific entry in matrix heatmap

12 views (last 30 days)
Given the matrix
A = rand(10,10);
We can visualize this with
heatmap(A);
I would like to "highlight" some fixed entries of A regardless of their values. For example, A(1,1) and A(3,2) as in the image
<<
>>
. One way would be to place an "X" on the specific values. Another would be to make the border around these entries bold.
How could one go about this efficiently?

Accepted Answer

Walter Roberson
Walter Roberson on 23 Oct 2017
You appear to be using the new heatmap() call, not the older biograph HeatMap() call.
Unfortunately, the new heatmap objects cannot have their text or decoration customized on a per-square basis.
You would need to figure out where the squares were on the display and text() the marking into place.
  3 Comments
Walter Roberson
Walter Roberson on 23 Oct 2017
Yes, it can be done. The most difficult part is figuring out the logic that was used to create the color map. It appears to me that it might have been constructed in HSV, with hue = 0.56612685560054 for each, with saturation mostly linear from 0.0760702186633815 to 1, and value quite linear from 0.9741 to 0.741
Once the colormap has been created, you can imagesc() and colormap() and colorbar(). set Xtick and YTick. Then you can text() any labels into place.
Note: the center of the upper left box is at (1,1), and the center of the lower right box is at (10,10). You can therefore use the nice integers to specify the location of your text -- but make sure that you set vertical and horizontal alignment to be 'center' so that the text you move in is centered in the square.
Benjamin Kraus
Benjamin Kraus on 6 Jan 2020
You can query the Colormap property on the heatmap to get the default colormap, but it was created using a fairly simple algorithm:
m = 256; % Desired number of colors
blue = [0 0.4470 0.7410]; % First color in ColorOrder
a = linspace(0.1,1,m)';
map = blue.*a + (1 - a);

Sign in to comment.

More Answers (0)

Categories

Find more on Data Distribution Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!