I have the following code which results in the heatmap shown:
indexnames2 = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K",
"L", "M"};
tblname = "Test Plot"
distmat = {{1.0, 0, 0, 0, 0, 0, 0.022, 0.015, 0, 0, 0, 0.0074}, {0,
1.0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 1.0, 0, 0, 0, 0, 0, 0,
0, 0, 0}, {0, 0, 0, 1.0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0,
1.0, 0, 0, 0, 0, 0, 0.45, 0}, {0, 0, 0, 0, 0, 1.0, 0, 0, 0, 0, 0,
0}, {0.022, 0, 0, 0, 0, 0, 1.0, 0.63, 0, 0, 0, 0.20}, {0.015, 0,
0, 0, 0, 0, 0.63, 1.0, 0, 0, 0, 0.12}, {0, 0, 0, 0, 0, 0, 0, 0,
1.0, 0.20, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0.20, 1.0, 0, 0}, {0,
0, 0, 0, 0.45, 0, 0, 0, 0, 0, 1.0, 0}, {0.0075, 0, 0, 0, 0, 0,
0.20, 0.12, 0, 0, 0, 1.0}};
ticks = Transpose[{Range[Length[indexnames2]], indexnames2}];
color[z_] :=
Which[z == 0, Blue, 0 < z < 1,
ColorData["TemperatureMap"][Rescale[z, {0, 1}]]]
Legended[MatrixPlot[distmat, ColorFunction -> color,
ColorFunctionScaling -> False, RotateLabel -> True,
ImageSize -> {500, 500},
PlotLabel -> Style[tblname, FontSize -> 18],
FrameTicks -> {ticks, None, None,
MapAt[Rotate[#, 90 Degree] &, ticks, {All, 2}]}],
BarLegend[{"TemperatureMap", {0, 1}}]]
I would like for the entries to be sorted so the most similar entities are shown in the top right and the least similar are shown in the bottom right. Is there a Mathematica function for this that would make the plot look more like the one shown below (I know this one is also not sorted but it does show some clustering like I want to achieve.)?
FindClusters
orFindGraphCommunities
. $\endgroup$ – Szabolcs May 8 '20 at 12:27FindClusters
can work with a pre-computed distance matrix, but perhaps you have the source data too. Sorry, no time for a full answer, but I hope these are useful references. $\endgroup$ – Szabolcs May 8 '20 at 12:29