MatrixPlot Styling

I like to build a colour sequence from a list. Each value has a corresponding colour.
I used MatrixPlot to do that. I have two question concerning MatrixPlot styling.

Code:

a = RandomInteger[{1, 4}, {50}];

MatrixPlot[{a},
ColorRules -> {1 -> Red, 2 -> Blue, 3 -> Green, 4 -> Gray},
Frame -> True,
Mesh -> True,
MeshStyle -> Black,
FrameTicks -> {{None, None}, {Table[i, {i, Length[a]}], None}}]

Question 1 :

I want to add my own labels on the ticks. For example at position 1 should stand a 2. If I use a list from running from 2 to 51, the labeling starts at the second position.

Question 2 :

I wonder if there is a way to add something to the plot. At the border of 9 and 10 for example I’d like to add a vertical line with text box.

=================

=================

1 Answer
1

=================

For the tick labels you can use Table[{i, 1 + i}, {i, 1, Length[a]}], and
to add a line and text you can use Epilog:

MatrixPlot[{a}, ColorRules -> {1 -> Red, 2 -> Blue, 3 -> Green, 4 -> Gray},
Frame -> True, Mesh -> True, MeshStyle -> Black,
FrameTicks -> {{None, None}, {Table[{i, 1 + i}, {i, 1, Length[a]}], None}},
ImageSize -> 900, PlotRangePadding -> {{1, 1}, {1, 2}},
Epilog -> {Thickness[.005], Black, Line[{{8, -.5}, {8, 1.5}}],
Text[Style[“flag”, 14, Red, “Panel”], {8., 2.}]}]

  

 

Thank you very much. Works perfectly!
– Peanut
Feb 6 ’15 at 15:35

  

 

@Peanut, my pleasure. Welcome to mma.se.
– kglr
Feb 6 ’15 at 18:16

  

 

There occurred another problem maybe you know something. I’d like to add a legend using PlotLegends. So far that’s no problem, but when I have more than five colors the legend is not displayed…
– Peanut
Feb 7 ’15 at 22:37

  

 

@Peanut, can you post an example of the PlotLegends issue– perhaps as a new question?
– kglr
Feb 8 ’15 at 23:08

  

 

Already did 😉 Problem solved. Have a nice day!
– Peanut
Feb 9 ’15 at 7:12