3
$\begingroup$

Teaching a unit on log scales for a high school math class.

I saw this table on the internet.

table

I know how to colour individual grid entries, is there a nice way to incrementally colour them like the sample image?

Here is a simple command line to create a bare bones table.... I'm looking to colour the entries as they are in the image (to accentuate the idea of "danger" to "okay")

Grid[{
  {"Environmental\nNoise", "Decibel\n  level"}, 
  {"Jet aircraft, 50 m away", "140"}, 
  {"Threshold of pain", "130"},
  {"Threshold of discomfort", "120"},
  {"Chainsaw, 1 m distance", "110"},
  {"Disco, 1 m from speaker", "100"},
  {"Diesel Truck, 10 m away", "90"}, 
  {"Kerbside of busy road, 5 m away", "80"},
  {"Vacuum, 1 m away", "70"},
  {"Conversational speech, 1 m", "60"},
  {"Average home", "50"},
  {"Quiet library", "40"},
  {"Quiet bedroom at night", "30"},
  {"Background in TV studio", "20"},
  {"Rustling leaves in the distance", "10"},
  {"Hearing threshold", "0"}}, Frame -> All, 
 Background -> {Automatic, Automatic, {{1, 1}, {1, 2}} -> LightGray}, 
 Alignment -> Left]
$\endgroup$
7
$\begingroup$

Try this:

Background -> {None, Prepend[Table[Hue[(k - 2)/35], {k, 15}], White]}

enter image description here

Pedagogical word of caution: this might not be the best example to give to grade-school students, as the bottom entry has a decibel level of zero; this may naturally lead students to think that the minimum possible decibel level is zero, which is false. Including examples of sounds with decibel levels below 0 might help to ensure this misconception dies in the crib.

Alternate:

Background -> {None, None, 
  Join[{{1, 1} -> LightGray, {1, 2} -> LightGray}, 
   Table[{k + 1, 2} -> Hue[(k - 2)/35], {k, 15}]]}

enter image description here

$\endgroup$
  • 1
    $\begingroup$ That looks fantastic, and simple to implement! $\endgroup$ – Tom De Vries Nov 4 '14 at 14:37
  • $\begingroup$ I appreciate the pedagogical note, that IS important. Sadly, those kinds of subtle nuances are lost on about 99% of my students (pardon my cynicism!) I'm happy if they actually understand a dB is a tenth of a Bel! $\endgroup$ – Tom De Vries Nov 4 '14 at 14:50
3
$\begingroup$

With data being your input text:

col = With[{l = Length[Last /@ data[[2 ;;]]]}, 
  Table[Blend[{Red, Yellow, Green}, x],{x, 0, 1, 1/(l - 1)}]];
Grid[data, Frame -> All, 
 Background -> {None, None, 
   Join[{{{1, 1}, {1, 2}} -> LightGray}, 
    Rule @@@ Thread@{{#, 2} & /@ Range[2, Length@data], col}]}, Alignment -> Left]

enter image description here

Or with Blend[{Green, Blue, Red}, x]:

enter image description here

or simply with ColorData["Rainbow"][x]:

enter image description here

$\endgroup$

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.