7
$\begingroup$

Is it possible to label the rows and columns of an ArrayPlot?

I have a somewhat large matrix, about 90x90. The rows and columns of this matrix have names. I want to plot this matrix using ArrayPlot, and I want to display labels indicating the names of the rows and columns. Ideally, column labels should be vertical, above the respective column, and row labels should be horizontal, at the side of the respective row.

How can this be done?

$\endgroup$
4
$\begingroup$

is this what you want?

tikc1 = {r1, r2, r3};
htick = {#, Style[tikc1[[#]], 14, Bold]} & /@ Range[3];
tikc2 = {c1, c2, c3, c4};
vtick = {#, Style[Rotate[tikc2[[#]], Pi/2], Bold, Red, 14]} & /@ 
  Range[4]; ArrayPlot[{{1, 0, 0, 0.3}, {1, 1, 0, 0.3}, {1, 0, 1, 
   0.7}}, FrameTicks -> {htick, vtick, htick, vtick}]

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ @becko, check update $\endgroup$ – Algohi Nov 18 '14 at 19:33
  • $\begingroup$ Almost. Only one more thing. The column labels should be rotated, otherwise they get scrambled. How can I do that? $\endgroup$ – becko Nov 18 '14 at 20:19
  • $\begingroup$ @becko, check update 2 $\endgroup$ – Algohi Nov 18 '14 at 20:24
7
$\begingroup$
data = RandomInteger[10, {20, 20}];

ticklabels = StringJoin /@ # & /@ RandomChoice[CharacterRange["A", "Z"], {2, 20, 3}];
ticklabels2 = MapAt[Rotate[#, Pi/2] &, ticklabels, {2, All}];
ticks = (MapIndexed[{First@#2, #1} &, #] & /@ ticklabels2);
ticks2 = {{ticks[[1]], None}, {None, ticks[[2]]}};

ArrayPlot[data, FrameTicks -> ticks2]

enter image description here

For labels on all sides use

 ticks2 =ticks[[{1,2,1,2}]]; 
 ArrayPlot[data, FrameTicks -> ticks2]

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ Could you add here how you do the simplest case i.e. 2x2 matrix with labels as in your first matrix, please, without randomisation. Also the entry could be simply numbers for the simplest case. $\endgroup$ – Léo Léopold Hertz 준영 Oct 13 '16 at 18:43
  • $\begingroup$ I am thinking how to visualise such big matrices with statistical values of sensitivity, specificity, np, pp and p here stats.stackexchange.com/q/240054/3017 I think some sort of graph can be more analytical to emphasize the densities and analytical statistics. However, I think those parameters are not sufficient and some sort of web should be made. $\endgroup$ – Léo Léopold Hertz 준영 Oct 13 '16 at 19:07

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.