I have a list of numbers, and I would like to plot them using ArrayPlot (which is easy, usually :)). I would like to be able to color the elements of the plot based on the average of the list: one color if the number is above average, another if it is below. I have tried a couple of things, but so far, no joy.
First thing I tried is have a module around the colorFun defined by me and the ArrayPlot, to calculate the mean, since I don't want it to be kernel-wide (many other plots will come with the same technique), and then define, inside the module, the colorFun:
Module[
{a, mean, colorFun},
a = RandomInteger[{0, 100}, 100];
mean = Mean[a];
colorFun[z_] := If[z <= mean, Red, Blue];
ArrayPlot[List@a, ImageSize -> Full, ColorFunction -> colorFun]
]
but this didn't work, since the plot would return all in the same color. It's actually not clear to me why.
I also tried to move colorFun in the form:
colorFun[z_]=RGBColor[{ , , }]
with 2 functions of z and mean for two elements and 0 for the third. The idea of using this approach instead of the if is that I could blend the colors (the further from the average, the more intense/bright the color I am plotting with).
Any ideas?
Thanks!
ColorFunctionScaling -> False
... $\endgroup$colorFun[]
so that it takes arguments in the interval $[0,1]$. $\endgroup$