[Date Index]
[Thread Index]
[Author Index]
Fwd: ColorFunction help?
*To*: mathgroup at smc.vnet.net
*Subject*: [mg74932] Fwd: ColorFunction help?
*From*: "Jean-Marc Gulliet" <jeanmarc.gulliet at gmail.com>
*Date*: Thu, 12 Apr 2007 04:44:43 -0400 (EDT)
*References*: <evfklp$75d$1@smc.vnet.net> <461B7FE0.2010102@gmail.com>
AES 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**.
>
The behavior you describe is expected. Evaluate the following
expressions and look at the full form of, say, gCP.
gCP is a graphic object, which has been evaluated on line 3. You can
notice that the structure of a graphic object is a list of points (or
list of lists, etc), points that are not going to be evaluated again,
and a list of options in the form of transformation rules, options that
will be evaluated every time you ask to draw the plot.
Therefore, the first time the plot is drawn, the current definition of
the function red is the one displayed in line 2b. Then, this definition
is changed by the one displayed on line 5b. (Note that at this stage
Mathematica has forgotten everything about the previous definition of red.)
When you call the function Show on line 7, the options of gCP are
evaluated again, and, this time, the current definition of red is the
one displayed on line 5b. Consequently, both graphics call the same
current, and only existing, definition of the function red, which colors
the plots in green.
(* lines 1 and 2 *)
k1 = 0; k2 = 1; k3 = 1;
red[i_] = RGBColor[1 - k1*i, 1 - k2*i, 1 - k3*i];
(* line 2b *)
Information["red", LongForm -> False]
(* line 3*)
gCP = ContourPlot[(x + y)/2, {x, 0, 1}, {y, 0, 1},
ColorFunction -> red];
(* lines 4 and 5 *)
k1 = 1; k2 = 0; k3 = 1;
red[i_] = RGBColor[1 - k1*i, 1 - k2*i, 1 - k3*i];
(* line 5b *)
Information["red", LongForm -> False]
(* lines 6 and 7 *)
gDP = DensityPlot[(x + y)/2, {x, 0, 1}, {y, 0, 1},
ColorFunction -> red];
Show[GraphicsArray[{{gCP, gDP}}]];
(* line 8 *)
FullForm[gCP]
Hope this helps,
Jean-Marc
Prev by Date:
**Re: Re: question**
Next by Date:
**Re: Re: Can Maximize return a function**
Previous by thread:
**Re: ColorFunction help?**
Next by thread:
**bug in Integrate (5.2)**
| |