Mathematica Asked by Conor Cosnett on May 20, 2021
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, #] &)]
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.
MatrixPlot[MapIndexed[Lighter[ColorData[97][#2[[2]]], #] &, matrix, {2}]]
MatrixPlot[MapIndexed[Lighter[{Red, Blue, Green}[[#2[[2]]]], #] &, matrix, {2}]]
MatrixPlot[MapIndexed[
Lighter[ColorData["Rainbow"][(#2[[2]] - 1)/(Dimensions[matrix][[2]] - 1)], #] &,
matrix, {2}]]
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])}]
Answered by kglr on May 20, 2021
Apparently ArrayPlot
accepts a matrix of color swatches.
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]
Answered by Conor Cosnett on May 20, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP