Skip to main content
edited body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
m = {{2, 0}, {1, 1}};
k = {"A", "B"};
MatrixPlot[m, ColorRules -> {0 -> White}, Frame -> True, 
 FrameLabel -> {"actual", "predicted"}, 
 FrameTicks -> {{MapIndexed[{#2[[1]], #} &, k], 
    MapIndexed[{#2[[1]], #} &, Total@Transpose@m]}, 
   {MapIndexed[{#2[[1]], #} &, Total[m]], 
    MapIndexed[{#2[[1]], #} &, k]}}, 
 ColorFunction -> "Rainbow", 
 Epilog -> MapIndexed[Text[Style[#, 16], #2 - 1/2] &, Transpose@Reverse@m, {2}]]

enter image description hereenter image description here

m = {{2, 0}, {1, 1}};
k = {"A", "B"};
MatrixPlot[m, ColorRules -> {0 -> White}, Frame -> True, 
 FrameLabel -> {"actual", "predicted"}, 
 FrameTicks -> {{MapIndexed[{#2[[1]], #} &, k], 
    MapIndexed[{#2[[1]], #} &, Total@Transpose@m]}, 
   {MapIndexed[{#2[[1]], #} &, Total[m]], 
    MapIndexed[{#2[[1]], #} &, k]}}, 
 ColorFunction -> "Rainbow", 
 Epilog -> MapIndexed[Text[Style[#, 16], #2 - 1/2] &, Transpose@Reverse@m, {2}]]

enter image description here

m = {{2, 0}, {1, 1}};
k = {"A", "B"};
MatrixPlot[m, ColorRules -> {0 -> White}, Frame -> True, 
 FrameLabel -> {"actual", "predicted"}, 
 FrameTicks -> {{MapIndexed[{#2[[1]], #} &, k], 
    MapIndexed[{#2[[1]], #} &, Total@Transpose@m]}, 
   {MapIndexed[{#2[[1]], #} &, Total[m]], 
    MapIndexed[{#2[[1]], #} &, k]}}, 
 ColorFunction -> "Rainbow", 
 Epilog -> MapIndexed[Text[Style[#, 16], #2 - 1/2] &, Transpose@Reverse@m, {2}]]

enter image description here

Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

m = {{2, 0}, {1, 1}};
k = {"A", "B"};
MatrixPlot[m, ColorRules -> {0 -> White}, Frame -> True, 
 FrameLabel -> {"actual", "predicted"}, 
 FrameTicks -> {{MapIndexed[{#2[[1]], #} &, k], 
    MapIndexed[{#2[[1]], #} &, Total@Transpose@m]}, 
   {MapIndexed[{#2[[1]], #} &, Total[m]], 
    MapIndexed[{#2[[1]], #} &, k]}}, 
 ColorFunction -> "Rainbow", 
 Epilog -> MapIndexed[Text[Style[#, 16], #2 - 1/2] &, Transpose@Reverse@m, {2}]]

enter image description here