MATLAB Answers

Generating a heat map of adjacency matrix

11 views (last 30 days)
Joseph Turner
Joseph Turner on 10 Apr 2021
Edited: dpb on 12 Apr 2021
I am trying to generate a heat map of an adjacency matrix from a particular graph with only two colours (a 100 x 100 array of squares).
I have the following code so far, with G1 being my function:
B=adjacency(G1);
adj=full(B);
heatmap(B)
Any help would be appreciated

Accepted Answer

dpb
dpb on 11 Apr 2021
Edited: dpb on 12 Apr 2021
Presuming you want the displayed values of the cells to still be their totals, then
s = [1 1 1 2 2 3];
t = [2 3 4 5 6 7];
G = digraph(s,t);
A = adjacency(G);
hHM=heatmap(B);
hHM.Colormap=[ones(1,3);zeros(max(hHM.ColorData(:)),3)];
will set the colormap to two-tone of black-white for zero-nonzero values. You can change the hue by modifiying the RGB ratio of the ones() array to suit.
The color data are what are in the data cells and scaled against the colormap -- you get the same colors by
hHM=heatmap(double(B>0));
but the cell values displayed will only be 0|1. You have to change the colormap scaling to map the colors by faking interpolation such that the breakpoint is between zero and the minumn number of connections.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by