Re: Coloring cells

• To: mathgroup at smc.vnet.net
• Subject: [mg83604] Re: Coloring cells
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Sat, 24 Nov 2007 04:14:37 -0500 (EST)
• Organization: The Open University, Milton Keynes, UK
• References: <fhrrsj\$5gh\$1@smc.vnet.net> <fhu7ui\$7fh\$1@smc.vnet.net> <200711210758.CAA06030@smc.vnet.net> <fi6aku\$ooh\$1@smc.vnet.net>

```Jamie Coventry wrote:

> I'm presenting data in a square arrangement and am trying to
> highlight specific cells in it which have something in common, e.g.
> all are prime, or all are odd numbers. I don't mind if the data is in
> an array/matrix/table, as long as it is n x n.
>
> myData = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
>
> How do I either color the text or the background of a particular
> cell, based on a rule (e.g. how could I color just 2, 3, 5, and 7 in
> the data given)?

The help pages for *Grid* and *Item* contain numerous and well
illustrated examples of such things. With the data set you provided, one
way of highlighting the primes, among many others, could be as follows,

myData = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
Grid[myData /. p_ /; PrimeQ[p] -> Item[p, Background -> Orange],
Frame -> True, FrameStyle -> Directive[Orange, Thickness[2]]]

Regards,
--
Jean-Marc

```

• Prev by Date: Re: Contour Lines
• Next by Date: Re: VectorFieldPlot Arrows
• Previous by thread: Re: Coloring cells
• Next by thread: SeriesCoefficient: needs work!