0
$\begingroup$

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};
$\endgroup$
2
  • $\begingroup$ 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? $\endgroup$
    – C. E.
    Oct 17, 2013 at 13:01
  • $\begingroup$ 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 $\endgroup$ Oct 17, 2013 at 13:26

1 Answer 1

2
$\begingroup$

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

$\endgroup$

Your Answer

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

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