13
$\begingroup$

I have this code:

AllData = Import["https://pastebin.com/raw/7RLL1Jw8", "Table"];
Temp0 = 25;
Do[Spec[2*i] = AllData[[All, (2*i + 1) ;; (2*i + 2)]], {i, 0, 8}];
Do[TotCts[2*i] = {5*i + Temp0, 
Integrate[Interpolation[Spec[2*i], InterpolationOrder -> 3][x], {x, 682,715}], 
Integrate[Interpolation[Spec[2*i], InterpolationOrder -> 3][x], {x, 715,745}], 
Integrate[Interpolation[Spec[2*i], InterpolationOrder -> 3][x], {x,745,770}]}, {i, 0, 8}];
DataPoints = N[Table[TotCts[2*i], {i, 0, 8}]];
mem = {●, ■, ◆};
cdata = Transpose[DataPoints[[All, 2 ;; 4]]];
ccm = Correlation[Transpose@cdata]; 
p2 = Column[{GraphicsRow[mem, ImageSize -> 200, Frame -> All, 
BaseStyle -> Directive["TR", FontSize -> 16, Black]],Row[{GraphicsColumn[mem, ImageSize -> {200/3, 200}, Frame -> All, 
  BaseStyle -> Directive["TR", FontSize -> 16, Black]], 
 Overlay[{ArrayPlot[ccm, 
    ColorFunction -> (ColorData["GrayTones"][(1 + #)/2] &), 
    Frame -> None, Mesh -> True, PlotRangePadding -> 0, 
    ImageSize -> {200, 200}, ColorFunctionScaling -> False], 
   GraphicsGrid[Map[NumberForm[#, 2] &, ccm, {2}], 
    ImageSize -> {200, 200}, 
    BaseStyle -> Directive["TR", FontSize -> 16, Black]]}]}]}, Alignment -> Right, Spacings -> 0]

Which generates this:

enter image description here

Is it possible to output a better looking table without those gaps between the top row and left column to the main table?

$\endgroup$
15
$\begingroup$

Grid

ClearAll[labeledGrid]
labeledGrid[cs_: "GrayTones", is_: {80, 80}, 
  sty_: Directive["TR", FontSize -> 16, Black]] := 
    Module[{tbl = Map[Item[Pane[Style[If[NumericQ@#, NumberForm[#, 2], #],  sty], 
       Alignment -> Center, ImageSize -> is], 
       Background -> If[NumericQ@#, ColorData[cs][(1 + #)/2], None]] &, 
     Prepend[Join[List /@ #2, #, 2], Prepend[#2, ""]], {2}]},
    Grid[tbl, Dividers -> {All, All, {{1, 1} -> False}}, ##3]] &;

labeledGrid[][ccm, mem, FrameStyle -> Gray]

enter image description here

labeledGrid["Rainbow", {50, 50}][ccm, mem, FrameStyle -> Gray]

enter image description here

ArrayPlot

ClearAll[labeledArrayPlot]
labeledArrayPlot[cs_: "GrayTones"] :=  Module[{epilog = 
      MapIndexed[Text[Style[# /. x_?NumericQ -> Round[x, 0.01], 
          Directive["TR", FontSize -> 16, Black]], #2 - .5] &, 
       Reverse /@ Transpose@ Prepend[Join[List /@ #2, #, 2], Prepend[#2, ""]], {2}]},
    ArrayPlot[ArrayPad[#, {{1, 0}, {1, 0}}, White]  , 
     ColorFunction -> ( ColorData[cs][(1 + #)/2] &), 
     Epilog -> epilog, ##3,
     ColorFunctionScaling -> False, Mesh -> All, ImageSize -> 1 -> 80]] &;

labeledArrayPlot[][ccm, mem]

enter image description here

SeedRandom[1]
mat = RandomReal[1, {7, 7}];
labels = StringTake[#, 3] & /@ RandomWord[7];

labeledArrayPlot["Rainbow"][mat, labels, ImageSize -> 1 -> 50]

enter image description here

$\endgroup$
9
$\begingroup$

How about using MatrixPlot?

epilog = MapIndexed[Text[Style[Round[#, .01], 10], #2 - 1/2] &, Transpose@Reverse@ccm, {2}];
ticks = Transpose[{Range@Length@mem, mem}];

MatrixPlot[ccm,
 Epilog -> epilog,
 FrameTicks -> {ticks, ticks, ticks, ticks},
 PlotRangePadding -> None,
 ColorFunction -> (ColorData["GrayTones"][(1 + #)/2] &),
 ColorFunctionScaling -> False]

enter image description here

$\endgroup$
9
$\begingroup$

Readapting my answer here: DensityPlot with text

dim = Dimensions@ccm;

temp = Transpose[{mem}~Join~Transpose@Round[ccm, .01]];
table = Prepend[temp, Flatten@{"", mem}];

background = 
  Join[{None, 
    None}, {Flatten[
     Table[{i, j} -> ColorData["GrayTones"][table[[i, j]]], {i, 2, 
       1 + dim[[1]]}, {j, 2, 1 + 3}], 1]}];

Grid[table
 , Frame -> All
 , Background -> background
 , Alignment -> Center
 , ItemSize -> All
 , Spacings -> {3, 4}
 , ItemStyle -> {{Directive[Black, Bold], Automatic}
   , {Directive[Black, Bold], Automatic}}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.