Highlight specific entry in matrix heatmap
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
matpylab
am 23 Okt. 2017
Kommentiert: Benjamin Kraus
am 6 Jan. 2020
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?
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 23 Okt. 2017
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 Kommentare
Walter Roberson
am 23 Okt. 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
am 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);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Distribution Plots 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!