1
$\begingroup$

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.

$\endgroup$
5
$\begingroup$

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.}]}]

enter image description here

$\endgroup$
  • $\begingroup$ Thank you very much. Works perfectly! $\endgroup$ – Peanut Feb 6 '15 at 15:35
  • $\begingroup$ @Peanut, my pleasure. Welcome to mma.se. $\endgroup$ – kglr Feb 6 '15 at 18:16
  • $\begingroup$ 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... $\endgroup$ – Peanut Feb 7 '15 at 22:37
  • $\begingroup$ @Peanut, can you post an example of the PlotLegends issue-- perhaps as a new question? $\endgroup$ – kglr Feb 8 '15 at 23:08
  • $\begingroup$ Already did ;) Problem solved. Have a nice day! $\endgroup$ – Peanut Feb 9 '15 at 7:12

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.