Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

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

Search the Archive

Re: ColorFunction help?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg74914] Re: ColorFunction help?
  • From: "Szabolcs" <szhorvat at gmail.com>
  • Date: Wed, 11 Apr 2007 01:55:49 -0400 (EDT)
  • References: <evfklp$75d$1@smc.vnet.net>

On Apr 10, 11:16 am, AES <siegman at stanford.edu> wrote:
> Some time back I asked about creating what a respondent later called
> "White to Color" color functions for contour and density plots, and
> after some further experimentation I've found that if I define
>
>       k1=xx;  k2=yy;  k3=zz;
>       myPlotColor[i_] = RBGColor[1 - k1 i, 1 - k2 i, 1 - k3 i]
>
> with k1, k2, k3 each set equal to either 0 or 1, and then use
>
>       ColorFunction->myPlotColor
>
> in the plot command, I get just the results I want.  For example if I
> execute the seven lines (either in a single cell or as separate cells)
>
>    k1 = 0; k2 = 1; k3 = 1;
>
>    red[i_] = RGBColor[1 - k1 i, 1 - k2 i, 1 - k3 i];
>
>    gCP = ContourPlot[(x + y)/2, {x, 0, 1}, {y, 0, 1},
>             ColorFunction -> red];
>
>    k1 = 1; k2 = 0; k3 = 1;
>
>    green[i_] = RGBColor[1 - k1 i, 1 - k2 i, 1 - k3 i];
>
>    gDP = DensityPlot[(x + y)/2, {x, 0, 1}, {y, 0, 1},
>             ColorFunction -> green];
>
>    Show[GraphicsArray[{{gCP, gDP}}]];
>
> I get the beautiful red ContourPlot  gCP that I want from lines 1 thru
> 3; the beautiful green DensityPlot  gDP  that I want from lines 4 thru
> 6; and then the two of them together from line 7.
>
> What puzzles me, however, is that if I replace the string "green" by
> "red" in lines 5 and 6 above, the individual plots CP and DP from lines
> 1 thbru 6 still come out red and green as before --- but the two
> graphics produced by the Show[ ] command in line 7 now both come out
> green.
>
> The DP resulting from line 6 obviously knew it was supposed to be green
> when it was first rendered, even though its ColorFunction was
> confusingly named "red", because red[i_] had been redefined using k
> values appropriate to green in line 5.  How come it forgets all about
> this when Show time comes around?
>
> [Email cc of replies welcomed]
>
> come out green**.

ContourPlot outputs a ContourGraphics object. You can check by using
FullForm that this object still contains ColorFunction->red. The
colour function is used when the graph is drawn, not when the
ContourGraphics object is generated.

You can convert it to an "expanded" graphics object by
gCP = Graphics[gCP]
In this new object the colours are hard-coded and they will not change
if you redefine red[].

Tip: use Hue[0, #, 1]& as your colour function. You can easily vary
the colour by changing the first parameter in Hue.

Szabolcs



  • Prev by Date: Re: Re: Question
  • Next by Date: Re: RootSum
  • Previous by thread: Re: convergence conditions correction
  • Next by thread: Re: ColorFunction help?