Highlight specific entry in matrix heatmap

12 次查看(过去 30 天)
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?

采纳的回答

Walter Roberson
Walter Roberson 2017-10-23
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 个评论
Walter Roberson
Walter Roberson 2017-10-23
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 2020-1-6
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);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by