3
$\begingroup$

I have a MatrixPlot that I would like to improve by adding labels.

The Matrix is composed with : - 14 columns, - 6 lines.

Instead of the graduation of the matrix, I would like to specify this labels :

  • for the columns {"a","b","c","d","e","f","g","h","i","j","k","l","m","n"}
  • for the lines {"eq1","eq2","eq3","eq4","eq5","eq6"}

How can I put this labels instead the current graduation ?

enter image description here

$\endgroup$

1 Answer 1

5
$\begingroup$
collabels =  CharacterRange["a", "n"]; 
rowlabels = Row[{"eq", #}] & /@ Range[6];
rowticks = Thread[{Range[6], rowlabels}];
colticks = Thread[{Range[14], collabels}];
dat = RandomInteger[5, {6, 14}];
MatrixPlot[dat, FrameTicks -> {rowticks, colticks}]

Mathematica graphics

Or use

FrameTicks -> {rowticks, colticks,rowticks, colticks}]

to label all four sides:

Mathematica graphics

MatrixPlot[dat, FrameTicks -> {None, None, rowticks, colticks}]

Mathematica graphics

$\endgroup$
6
  • $\begingroup$ Perfect! Thanks a lot. I would like to do a slight modification. Instead of the list {"a","b","c","d","e","f","g","h","i","j","k","l","m","n"}, I would like to use a list of variables of my problems T={a,b,c,d,e,f,g,h,i,j,k,l,m,n}. So I have tried to do like this map(ToString,T) so as to convert my list of variables into a list of strings but it seems that it doesn't work. Do you have ideas ? $\endgroup$
    – Bendesarts
    Feb 27, 2016 at 18:08
  • 2
    $\begingroup$ @Bendesarts map(...) isn't valid MMA syntax. $\endgroup$
    – LLlAMnYP
    Feb 27, 2016 at 18:51
  • $\begingroup$ Perfect! and how can I do to put the rowticks only on the right and the colticks only on the top ? $\endgroup$
    – Bendesarts
    Feb 28, 2016 at 8:42
  • 1
    $\begingroup$ @Bendesarts, you can use FrameTicks -> {None, None, rowticks, colticks}]. $\endgroup$
    – kglr
    Feb 28, 2016 at 9:37
  • 1
    $\begingroup$ @Bendesarts, tick labels do not have to be strings; you should be able to use subscripted symbols. Can you give an example of variables that is giving you trouble? $\endgroup$
    – kglr
    Feb 28, 2016 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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