# Color a grid of ArrayPlots using total value of each array

This Seems like it should be relatively straight-forward, but I am struggling to find an answer. I would like to color each ArrayPlot in a GraphicsGrid by its Total. I can get the grid of ArrayPlots, but all of my efforts to assign color on the basis of Total have failed. Here is what I have at this juncture.

list = {0, 1}
b2 = Tuples[list, 4]
nn = Length[b2]
b2sort = Sort[b2, Total[#1] < Total[#2] &]
GraphicsGrid[
Partition[
Table[ArrayPlot[ ArrayReshape[b2sort[[n]], {2, 2}], Mesh -> All,
ImageSize -> 1 -> 25], {n, nn}], 4], PlotLabel -> "stuff"]


Ideally, each array that was produced would be given a unique color (for the entire array) that depended upon the total for that array (i.e., the numbers 0, 1, 2, 3 or 4). Any color function at this juncture would be fine. The idea is that all arrays with total=0 would be a unique color, all with total=1 would be a different unique color, etc.

Any help would be appreciated.

• what is the value of var nn? – J42161217 Apr 23 '19 at 20:45
• My apologies-- I meant to make that self-standing. nn is the number of elements in the set generated by Tuples. I have modified the code to put that crucial bit of information in. – d3e5560 Apr 23 '19 at 21:08

is this what you are looking for?

list={0,1}
b2=Tuples[list,4]
nn = Length[b2]
b2sort=Sort[b2,Total[#1]<Total[#2]&]
GraphicsGrid[Partition[Table[ArrayPlot[ArrayReshape[b2sort[[n]],{2,2}],Mesh->All,
ImageSize->1->25,ColorRules->{1->ColorData[1,Total@b2sort[[n]]],0->White}],
{n,nn}],4],PlotLabel->"stuff"]


• Yes-- that is exactly what I was looking for. Thanks- I learned something super helpful here! – d3e5560 Apr 23 '19 at 21:09
• I'm glad I helped! Also keep in mind that by changing the first value of ColorData , you are changing color schemes – J42161217 Apr 23 '19 at 21:14