Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Background Subregions in Mathematica Grid

I can`t figure out how to define several subregions with different color background as in the below.

Any Idea ?

Many thanks,

LA

Grid[Table["g", {4}, {7}],
Background -> {None, None, {{{1, 3}, {1, 3}} -> LightRed}}]
like image 865
500 Avatar asked May 25 '11 12:05

500


2 Answers

Just as a side note, a usual requirement is to specify background colors depending on values.

For that you can do:

k = Table[RandomInteger[{1, 2}], {4}, {7}];
Grid[k,
 Background ->
  {None, None,
   Join[
    Position[k, 1] /. {x_, y_} -> ({x, y} -> LightRed), 
    Position[k, 2] /. {x_, y_} -> ({x, y} -> LightBlue)]
   }]

enter image description here

Edit

If you don't know a priori the range of values, you may try something like:

k = Table[RandomInteger[{1, 20}], {4}, {7}];
Grid[k,
 Frame -> All,
 ItemStyle -> Directive[FontSize -> 16], 
 Background ->
  {None, None, 
   Flatten@Array[List[##] ->
                   ColorData["Rainbow"][(k[[##]] - Min@k) / Max@k] &, 
           Dimensions@k]
  }  
]

enter image description here

like image 111
Dr. belisarius Avatar answered Nov 01 '22 16:11

Dr. belisarius


Simply list the regions and colors as you already have the first one:

Grid[Table["g", {4}, {7}], 
 Background -> {None, None, {
    {{1, 3}, {1, 3}} -> LightRed,
    {{3, 4}, {4, 7}} -> LightBlue
  } } ]

enter image description here

like image 42
Mr.Wizard Avatar answered Nov 01 '22 15:11

Mr.Wizard