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

How To invert ColorFunction

1,121 views
Skip to first unread message

Vladimir

unread,
Jan 21, 2010, 6:32:59 AM1/21/10
to
Hi everybody,

I am plotting Zernike-Polynomials like this:

---------
c4 = 1;

z4[rho_, theta_] := rho^2*Cos[2*theta]

RevolutionPlot3D[c4*z4[rho, theta], {rho, 0, 1}, {theta, 0, 2*Pi},
ColorFunction -> "Rainbow"]
---------

To be able to compare the plot to measured data from an
interferometer, I would like to invert the Rainbow colouring, that is
red at the bottom and blue on top. However, I can't find to work this
out. Does anyone know how to do this?

Thank you,
Vladimir.

van der Burgt, Maarten

unread,
Jan 22, 2010, 5:35:38 AM1/22/10
to
Vladimir,

RevolutionPlot3D[c4*z4[rho, theta], {rho, 0, 1}, {theta, 0, 2*Pi},

ColorFunction -> (ColorData["Rainbow"][1 - #3] &)]

does the job.

regards,

Maarten

dr DanW

unread,
Jan 22, 2010, 5:36:00 AM1/22/10
to
Vladimir,

ColorFunction->"Rainbow"

is shorthand for

ColorFunction -> Function[{x, y, z}, ColorData["Rainbow"][z]

where z is the value of the dependent variable scaled to be between 0
and 1. So, to invert the colors, flip the scale to z is scaled to be
between 1 and 0:

ColorFunction -> Function[{x, y, z}, ColorData["Rainbow"][1 - z]]

To learn more, look up ColorFunction, ColorData, ColorDataFunction,
and Color Schemes in the Doc Center.

Daniel

Vivek Joshi

unread,
Jan 22, 2010, 5:36:11 AM1/22/10
to
On 1/21/10 5:31 AM, Vladimir wrote:
> Hi everybody,
>
> I am plotting Zernike-Polynomials like this:
>
> ---------
> c4 = 1;
>
> z4[rho_, theta_] := rho^2*Cos[2*theta]
>
> RevolutionPlot3D[c4*z4[rho, theta], {rho, 0, 1}, {theta, 0, 2*Pi},
> ColorFunction -> "Rainbow"]
> ---------
>
> To be able to compare the plot to measured data from an
> interferometer, I would like to invert the Rainbow colouring, that is
> red at the bottom and blue on top. However, I can't find to work this
> out. Does anyone know how to do this?
>
> Thank you,
> Vladimir.
>
>
c4 = 1;

z4[rho_, theta_] := rho^2*Cos[2*theta]

RevolutionPlot3D[c4*z4[rho, theta], {rho, 0, 1}, {theta, 0, 2*Pi},

ColorFunction -> (ColorData["Rainbow", 1 - #3] &)]

Vivek

David Park

unread,
Jan 22, 2010, 5:38:03 AM1/22/10
to
The question is: what are the arguments to the ColorFunction? One can
usually find this by looking on the ColorFunction Help page where they list
(in More Information) the arguments for various plot types. But I can't find
RevolutionPlot3D listed there.

However, on the RevolutionPlot3D page, Examples, Options, ColorFunction,
first example WRI does give the ordering of the parameters. These are:

{x, y, z, t, \[Theta], r}

I don't know exactly how you want to color the surface. Suppose you want to
color according to the z value and use the reverse gradient. Then you could
write:

c4 = 1;
z4[rho_, theta_] := rho^2 Cos[2 theta]

RevolutionPlot3D[c4 z4[rho, theta], {rho, 0, 1}, {theta, 0, 2 \[Pi]},
ColorFunction -> (ColorData["Rainbow"][1 - #3] &)]

You could also write this as:

RevolutionPlot3D[c4 z4[rho, theta], {rho, 0, 1}, {theta, 0, 2 \[Pi]},
ColorFunctionScaling -> False,
ColorFunction -> (ColorData["Rainbow"][Rescale[#3, {1, -1}]] &)]

Or as:

RevolutionPlot3D[c4 z4[rho, theta], {rho, 0, 1}, {theta, 0, 2 \[Pi]},
ColorFunctionScaling -> False,
ColorFunction -> (ColorData["Rainbow"][
Rescale[#3, {-1, 1}, {1, 0}]] &)]

The usefulness of that construction is if your wanted to write your own
color function as a function of the actual parameters. Then you could find
the minimum and maximum values over the surface and use Rescale to fit it to
a gradient, a reverse gradient or even a part of a gradient.

Notice also that in Version 7, if one uses a ColorFunction on various
surface plots, Mathematica uses Lighting -> "Neutral". This is nice because
the color of the lights won't overwhelm pastel colored surfaces.


David Park
djm...@comcast.net
http://home.comcast.net/~djmpark/

Leonid Shifrin

unread,
Jan 22, 2010, 5:38:14 AM1/22/10
to
Hi Vladimir,

This seems to do what you want:

RevolutionPlot3D[c4*z4[rho, theta], {rho, 0, 1}, {theta, 0, 2*Pi},

ColorFunction -> (ColorData["Rainbow"][1 - #3] &)]

Regards,
Leonid

Eric G

unread,
Jan 22, 2010, 5:38:25 AM1/22/10
to
Hi Vladimir,
try this:

c4 = 1;

z4[rho_, theta_] := rho^2*Cos[2*theta];

min = -1 (* the minimun in your z axis*);
max = 1 (*...maximun ....*);

RevolutionPlot3D[c4*z4[rho, theta], {rho, 0, 1}, {theta, 0, 2*Pi},

ColorFunction -> (ColorData["Rainbow"][(#3 - min)/(max - min)] &),
ColorFunctionScaling -> False]

----- Original Message -----
From: "Vladimir" <svetl...@yahoo.de>
To: <math...@smc.vnet.net>
Sent: Thursday, January 21, 2010 3:31 AM
Subject: How To invert ColorFunction

Bob Hanlon

unread,
Jan 22, 2010, 5:39:37 AM1/22/10
to

RevolutionPlot3D[c4*z4[rho, theta],
{rho, 0, 1}, {theta, 0, 2*Pi},
ColorFunction -> (ColorData["Rainbow"][1 - #3] &)]


Bob Hanlon

---- Vladimir <svetl...@yahoo.de> wrote:

=============

Patrick Scheibe

unread,
Jan 22, 2010, 5:41:28 AM1/22/10
to
Hi,

what about

c4 = 1;

z4[rho_, theta_] := rho^2*Cos[2*theta]

RevolutionPlot3D[c4*z4[rho, theta], {rho, 0, 1}, {theta, 0, 2*Pi},

ColorFunction -> Function[{x, y, z}, ColorData["Rainbow"][1 - z]]]

?

Cheers
Patrick

Vladimir

unread,
Jan 23, 2010, 7:36:01 AM1/23/10
to

Hey there,

I did look up ColorFunction in the Documentation Center, but didn't
work out that I could enter [1-z] as the second argument. Thank you
all so much, now it works perfectly.

Bye,
Vlad.

0 new messages