Generating a heat map of adjacency matrix

조회 수: 10 (최근 30일)
Joseph Turner
Joseph Turner 2021년 4월 10일
편집: dpb 2021년 4월 12일
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

채택된 답변

dpb
dpb 2021년 4월 11일
편집: dpb 2021년 4월 12일
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.

추가 답변 (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