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}}]
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)]
}]
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]
}
]
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
} } ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With