Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: Re: Color coding a Table entry

  • To: mathgroup at smc.vnet.net
  • Subject: [mg92702] Re: [mg92688] Re: Color coding a Table entry
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Sat, 11 Oct 2008 06:42:07 -0400 (EDT)
  • Reply-to: hanlonr at cox.net

For plots use ColorFunction

Plot[(x - 1) (x - 4), {x, 0, 5}, 
 ColorFunction -> Function[{x, y}, If[y < 0, Blue, Red]],
 ColorFunctionScaling -> False]


Bob Hanlon

---- AES <siegman at stanford.edu> wrote: 

=============
Original post:

> I'm Printing (to the screen) a Table like, let's say,
> 
>    Table[{f1, f2, f3}, (x, xmin, xmax}]
> 
> and anytime the value of f2 goes negative I want that value printed in 
> Red.   What's a simple, compact way to code this?

Of the dozen or so replies, I'd say that

> Table[{f1, Style[f2, If[f2 < 0, Red, Black]], f3}, {x, -1, 5}]
> 
> 
> Bob Hanlon

is by far the best:  simple, clean, you can see what it does, no arcane 
symbols, no cross effects on anything else outside that entry (and, the 
solution I'd already come up with on my own).

If the conditional in the If[ ] statement got lengthy, to avoid 
cluttering up the Table with it I might go to the alternative suggestion

>     redneg[expr_] := If[cond[expr], Style[expr, Red], expr, expr]
>
>     With[{xmin = 0, xmax = 10},
<      Table[{f1, redneg[f2], f3}, {x, xmin, xmax}]]
<
>  Regards, Jean-Marc

Or, just define the conditional separately, outside the Table,

   cond[expr_] : = <<something>>

and use

        Style[f2, If[fcond[f2], Red, Black]]

in the Table.

Would  Plot[redneg[f[x]], {x, xmin, xmax}]  make the plot turn black 
below the x axis???   Have to try it and see . . .


--

Bob Hanlon



  • Prev by Date: Re: Mathematica vs Latex
  • Next by Date: Re: Prime Puzzle with Mathematica
  • Previous by thread: Re: Color coding a Table entry
  • Next by thread: Re: Color coding a Table entry