Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I need to add lables on the right from ArrayPlot for each row and color the black square of each row depending on values from two list. Color list has a numbers in some range and should be mapped using Color Scheme.

s={{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 0, 1, 1, 0}, {1, 1, 1, 1, 0, 1, 1, 1, 1, 0}, {1, 1, 1, 1, 0, 1, 1, 0, 1, 1}, {1, 1, 0, 1, 1, 1, 1, 1, 1, 0}, {1, 1, 0, 1, 1, 1, 1, 0, 1, 1}, {1, 1, 0, 1, 1, 0, 1, 1, 1, 1}, {0, 1, 1, 1, 1, 1, 1, 1, 1, 0}, {0, 1, 1, 1, 1, 1, 1, 0, 1, 1}, {0, 1, 1, 1, 1, 0, 1, 1, 1, 1}, {0, 1, 1, 0, 1, 1, 1, 1, 1, 1}, {0, 1, 1, 0, 1, 1, 0, 1, 1, 0}};
ArrayPlot[s, Mesh -> True]
labels = {638/2835, 37/432, 3/40, 1/16, 1/14, 1/20, 1/16, 8/81, 1/14, 3/40, 37/432, 1/27};
colors = {0.00, 0.74, 0.79, 0.86, 0.81, 0.93, 0.86, 0.67, 0.81, 0.79, 0.74, 1.00};
share|improve this question
    
1) What color does for example 638/2835 in your colors list correspond to? 2) When you say color a row, what exactly do you mean? Should each white square with that color be replaced with that color in that row, or should the label have that background? –  Pickett Oct 17 '13 at 13:01
    
1) Colors list represent numbers in some range and could be normalized as (Max[colors] - colors)/(Max[colors] - Min[colors]) for examle 2) I need to color only black squares –  Филипп Цветков Oct 17 '13 at 13:26
add comment

1 Answer

up vote 1 down vote accepted

While this information is available in the documentation, especially in the options section of ArrayPlot, here's the recap:

  • The color of each square is determined by its value in the matrix. So we have to replace each 0 with the right color. If some values are RGB values, all values should be, so for that reason we replace 1 as well.
  • To use frame ticks we need to set Frame -> True, however we don't want the frame so for that reason we hide it by settings its opacity to zero. This however will hide the ticks as well, so we have to explicitly restore their opacity.

Code:

frameticks = Transpose[{Range[Length[labels]], labels}];
colors = ColorData["AvocadoColors"] /@ ((labels - Min[labels])/(Max[labels]  - Min[labels]));
data = MapThread[# /. {0 -> #2, 1 -> White} &, {s, colors}];
ArrayPlot[data,
 Mesh -> True,
 Frame -> True,
 FrameStyle -> Opacity[0],
 FrameTicksStyle -> Opacity[1],
 FrameTicks -> {None, None, frameticks, None}
 ]

arp

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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