2
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ what is the value of var nn? $\endgroup$ – J42161217 Apr 23 '19 at 20:45
  • $\begingroup$ 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. $\endgroup$ – d3e5560 Apr 23 '19 at 21:08
4
$\begingroup$

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"]    

enter image description here

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

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.