MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Coloring cells


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!