3
$\begingroup$

Consider an ArrayPlot of some arbitrary matrix with values between zero and one.

matrix = {
          {0.1, 0.1, 0.1}
        , {0.3, 0.3, 0.3}
        , {0.5, 0.5, 0.5}
      };

I want to plot this matrix as an ArrayPlot but with each Column as a different color.

Using ColorFunction and Lighter I can make all the Columns the same color.

matrix = {{0.1, 0.1, 0.1}, {0.3, 0.3, 0.3}, {0.5, 0.5, 0.5}};
ArrayPlot[matrix, ColorFunction -> (Lighter[Red, #] &)]

Question:

How do I make each Column of the ArrayPlot shades of a different color?

For instance, I would like to make the cells of the first column shades of blue.

$\endgroup$
5
$\begingroup$
 MatrixPlot[MapIndexed[Lighter[ColorData[97][#2[[2]]], #] &, matrix, {2}]]

![enter image description here

MatrixPlot[MapIndexed[Lighter[{Red, Blue, Green}[[#2[[2]]]], #] &, matrix, {2}]]

enter image description here

MatrixPlot[MapIndexed[
  Lighter[ColorData["Rainbow"][(#2[[2]] - 1)/(Dimensions[matrix][[2]] - 1)], #] &, 
  matrix, {2}]]

enter image description here

You can also use Raster + Graphics:

Graphics[Raster[MapIndexed[List @@ Lighter[{Red, Blue, Green}[[#2[[2]]]], #] &, 
    Reverse @ matrix, {2}]],
  Frame -> True, 
FrameTicks -> {{#, #} &@({# - .5, 4 - #} & /@ Range[3]), 
   {#, #} &@({# - .5, #} & /@ Range[3])}]

enter image description here

$\endgroup$
3
$\begingroup$

Apparently ArrayPlot accepts a matrix of color swatches.

enter image description here

So one way of achieving the desired result is to replace all of the elements of the matrix with corresponding swatches. This can be done using the Lighter function

matrix = {{0.1, 0.1, 0.1}, {0.3, 0.3, 0.3}, {0.5, 0.5, 0.5}};
trans = Transpose[matrix];
swatchMatrix = Transpose[{
                           Lighter[ Red, #] & /@ trans[[1]]
                         , Lighter[ Blue, #] & /@ trans[[2]]
                         , Lighter[ Green, #] & /@ trans[[3]]
               }];

ArrayPlot[swatchMatrix]
$\endgroup$

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.