1
$\begingroup$

I want to draw a MatrixPlot and replace the FrameTicks with cities names, as shown bellow. The problem is that FrameTicks uses the string center to position it in the respective tick, which results in a bad alignment in the top section. How can I set it to use the left justified text?

ListaCidades = {"Aveiro", "Açores", "Beja", "Braga", "Bragança", 
   "Castelo Branco", "Coimbra", "Évora", "Faro", "Guarda", "Leiria", 
   "Lisboa", "Madeira", "Portalegre", "Porto", "Santarém", "Setúbal", 
   "Viana do Castelo", "Vila Real", "Viseu"};

MatrixPlot[Data1, 
 FrameTicks -> {{{#, Style[ListaCidades[[#]], 12]} & /@ Range[20], 
    None}, {None, {#, 
       Rotate[Style[ListaCidades[[#]], 12], 45 Degree]} & /@ 
     Range[20]}}, ImageSize -> Large]

enter image description here

$\endgroup$
1
  • $\begingroup$ I think is only similar but not quite the same. That one is asking to align to the center and from the replies I can't figure it out how to adapt to my problem. $\endgroup$
    – Miguel
    Sep 21, 2017 at 11:47

1 Answer 1

4
$\begingroup$

Like this:

ListaCidades = {"Aveiro", "Açores", "Beja", "Braga", "Bragança", 
   "Castelo Branco", "Coimbra", "Évora", "Faro", "Guarda", "Leiria", 
   "Lisboa", "Madeira", "Portalegre", "Porto", "Santarém", "Setúbal", 
   "Viana do Castelo", "Vila Real", "Viseu"};
Data1 = RandomReal[{0, 1}, {Length@ListaCidades, Length@ListaCidades}];

center = Row[{Invisible[#], #}, "\[NegativeThickSpace]"] &;

MatrixPlot[Data1, 
 FrameTicks -> {{{#, Style[ListaCidades[[#]], 12]} & /@ Range[20], 
    None}, {None, {#, 
       center@Rotate[Style[ListaCidades[[#]], 12], 45 Degree]} & /@ 
     Range[20]}}, ImageSize -> Large]

enter image description here

$\endgroup$

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