Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Question about ColorFunction

59 views
Skip to first unread message

Jee Lou

unread,
May 23, 2012, 3:30:22 AM5/23/12
to
Anyone explain to me how ColorFunction works? Why Plot3D[Sin[x + y], {x, 0, 3}, {y, 0, 3}, ColorFunction -> (Hue[Sin[#1 + #2]] &)] and Plot3D[Sin[x + y], {x, 0, 3}, {y, 0, 3}, ColorFunction -> (Hue[#3] &)] return different color distributions?

Bob Hanlon

unread,
May 24, 2012, 3:33:07 AM5/24/12
to
"With the usual default setting ColorFunctionScaling->True, all
arguments supplied to func are scaled to lie in the range 0 to 1."

In your first example, #1 and #2 are each scaled before being fed to
Sin[#1 + #2]] & so the argument of the Sin is in the interval {0, 2}.
In your second example, the argument of Hue[#3] & is in the interval
{0, 1}. The plots would be identical if you used ColorFunctionScaling
-> False in each.


Bob Hanlon

JiHui Lou

unread,
May 24, 2012, 3:34:08 AM5/24/12
to

Thx for replying.
But when option ColorFunctionScaling->False is added in both, the plots are
still different if u check them carefully...
As you remind me, "With the usual default setting
ColorFunctionScaling->True, all arguments supplied to func are scaled to
lie in the range 0 to 1." is helpful and inspiring. As a result, I have
tried Plot3D[Sin[x + y], {x, 0, 3}, {y, 0, 3}, ColorFunction ->
(Hue[Sin[Pi (#1 + #2)]] &)] to get the same plot as Plot3D[Sin[x + y], {x,
0, 3}, {y, 0, 3}, ColorFunction -> (Hue[#3] &)] produce, but unfortunately
they are still different.
So would u be so kind to help me find a way to make the same plot
as Plot3D[Sin[x + y], {x, 0, 3}, {y, 0, 3}, ColorFunction -> (Hue[#3] &)]
without using ColorFunction form Hue[#3]& but with other form including #1
and #2 ?
Thx a lot!







*=C2=A5=BC=AA=BB=D4 *=BE=B4=C9=CF From Jee Lou


*Jee Lou* *Student, Major: Physics, Zhejiang Normal University, Jinhua,
P.R.China*

Bob Hanlon

unread,
May 24, 2012, 3:34:38 AM5/24/12
to

On my system the two plots on the bottom row of the Grid below look the
same.


$Version


"8.0 for Mac OS X x86 (64-bit) (October 5, 2011)"


With[{is = ImageSize -> 300,
cfs = ColorFunctionScaling -> False},
Grid[{
{Plot3D[Sin[x + y], {x, 0, 3}, {y, 0, 3},
ColorFunction -> (Hue[Sin[#1 + #2]] &), is],
Plot3D[Sin[x + y], {x, 0, 3}, {y, 0, 3},
ColorFunction -> (Hue[#3] &), is]},
{Plot3D[Sin[x + y], {x, 0, 3}, {y, 0, 3},
ColorFunction -> (Hue[Sin[#1 + #2]] &), cfs, is],
Plot3D[Sin[x + y], {x, 0, 3}, {y, 0, 3},
ColorFunction -> (Hue[#3] &), cfs, is]}}]]


I recommend that you use Rescale to understand how the scaling affects the
output


data = Prepend[Flatten[Table[{
x, y, z = Sin[x + y],
xs = Rescale[x, {0, 3}],
ys = Rescale[y, {0, 3}],
Sin[Pi (xs + ys)],
Rescale[z, {-1, 1}]},
{x, 0, 3, .75}, {y, 0, 3, 0.75}], 1],
{"x", "y", "z=Sin[x+y]", "xs", "ys",
"Sin[Pi(xs+ys)]", "zs"}] // Grid



Bob Hanlon



On Wed, May 23, 2012 at 9:56 AM, JiHui Lou <ywdr...@gmail.com> wrote:

> Thx for replying.
> But when option ColorFunctionScaling->False is added in both, the plots
> are still different if u check them carefully...
> As you remind me, "With the usual default setting
> ColorFunctionScaling->True, all arguments supplied to func are scaled to
> lie in the range 0 to 1." is helpful and inspiring. As a result, I have
> tried Plot3D[Sin[x + y], {x, 0, 3}, {y, 0, 3}, ColorFunction ->
> (Hue[Sin[Pi (#1 + #2)]] &)] to get the same plot as Plot3D[Sin[x + y], {x=
,
> 0, 3}, {y, 0, 3}, ColorFunction -> (Hue[#3] &)] produce, but unfortunatel=
y
> they are still different.
> So would u be so kind to help me find a way to make the same plot
> as Plot3D[Sin[x + y], {x, 0, 3}, {y, 0, 3}, ColorFunction -> (Hue[#3] &)]
> without using ColorFunction form Hue[#3]& but with other form including #=
1
> and #2 ?
> Thx a lot!
>
>
>
>
>
>
>
> *=C2=A5=BC=AA=BB=D4 *=BE=B4=C9=CF From Jee Lou
>
>
> *Jee Lou* *Student, Major: Physics, Zhejiang Normal University, Jinhua,
> P.R.China*
>
> Tel: (+86) 15958451501 | Email: ywdr...@gmail.com
> Contact me: [image: Google Talk] ywdr...@gmail.com [image: MSN]
> yw...@live.cn [image: QQ] yw...@qq.com
> Reach me by the followings: [image: Facebook]<http://www.facebook.com/y=
wdr1987>
> [image: Twitter] <https://twitter.com/#!/ywdr1987> [image: Google Plus=
]<https://plus.google.com/101548232068182998139/about>
> [image: Blog RSS] <http://xiaochoublog.appspot.com/feed> [image:
> Blogger] <http://ywdr.blogspot.com/> [image: Google Reader]<https://www.=
google.com/reader/shared/ywdr1987>
> [image: Picasa] <https://picasaweb.google.com/ywdr1987> [image:
> YouTube] <http://youtube.com/user/ywdr1987> [image: Orkut]<http://www.or=
kut.com/Main#Profile?uid=10216865585918422690>
>
>
>
>
>
> On Wed, May 23, 2012 at 9:23 PM, Bob Hanlon <hanlo...@gmail.com> wrote:
>
>> "With the usual default setting ColorFunctionScaling->True, all
>> arguments supplied to func are scaled to lie in the range 0 to 1."
>>
>> In your first example, #1 and #2 are each scaled before being fed to
>> Sin[#1 + #2]] & so the argument of the Sin is in the interval {0, 2}.
>> In your second example, the argument of Hue[#3] & is in the interval
>> {0, 1}. The plots would be identical if you used ColorFunctionScaling
>> -> False in each.
>>
>>
>> Bob Hanlon
>>
>>
>> On Wed, May 23, 2012 at 3:29 AM, Jee Lou <ywdr...@gmail.com> wrote:
>> > Anyone explain to me how ColorFunction works? Why Plot3D[Sin[x + y],
>> {x, 0, 3}, {y, 0, 3}, ColorFunction -> (Hue[Sin[#1 + #2]] &)] and
>> Plot3D[Sin[x + y], {x, 0, 3}, {y, 0, 3}, ColorFunction -> (Hue[#3] &)]
>> return different color distributions?
>> >
>>
>
>


--
Bob Hanlon

Chris Degnen

unread,
May 24, 2012, 3:31:04 AM5/24/12
to
The explanation is alluded to in the 'MORE INFORMATION' section of the Help
on ColorFunction, at:

http://reference.wolfram.com/mathematica/ref/ColorFunction.html

I.e.

ColorFunction->"name" is equivalent to ColorFunction->(ColorData["name"][#i]&) where the slot used is as follows: Plot, ListPlot, etc.: #2 (y); ArrayPlot, ReliefPlot: #1 (a); ContourPlot, DensityPlot, etc.: #1 (f); ContourPlot3D, etc.: #4 (f); Plot3D, etc.: #3 (z).

So in your example:

Plot3D[Sin[x + y], {x, 0, 3}, {y, 0, 3}, ColorFunction -> (Hue[Sin[#1 + #2]] &)]

#1 and #2 are the x and y values respectively. You can see the effect if you just use Sin[#1] or Sin[#2].

Using #3 uses the z value.


Sseziwa Mukasa

unread,
May 24, 2012, 3:31:34 AM5/24/12
to

The arguments to ColorFunction are scaled, from the help documentation:

With the usual default setting ColorFunctionScaling->True, all arguments supplied to func are scaled to lie in the range 0 to 1.

Compare:

Plot3D[Sin[x + y], {x, 0, 3}, {y, 0, 3},
ColorFunction -> (Hue[(Sin[3 #1 + 3 #2] + 1)/2] &)]

Regards,
Sseziwa
0 new messages