How do I create my own color gradient?

984 views

Tyler

Oct 2, 2008, 6:49:05 PM10/2/08
to
Hi All:

Kinda of a silly question, but I've been banging head against the wall
for the past two nights. I am trying to figure out how I can make my
own colour gradient, analogous to Rainbow, AplineColors, &c.

Is there any standard framework around trying to create your own?
Further, say I wanted one of the preexisting ones, but scaled
exponentially, or set a particular value to bright yellow (to
highlight that specific result). I used to use IDL quite a bit, and
made use of these kinds of manipulations frequently.

Any ideas or references? I keep finding myself doing the same old loop
in the Documentation Center, from ColorData, to ColorFunction, and so
on, and so on.....

Cheers,

t.

Albert Retey

Oct 3, 2008, 6:41:12 AM10/3/08
to

the gradients are in the form of ColorFunctions. As almost everything
these are normal mathematica expressions that you can handle just like
any other expression. You can look at the FullForm of these to see the
data they contain:

ColorData["Rainbow"] // FullForm

What you will see is that it basically contains a pure function which
encapculates a Blend. With that information, adoptions and constructions
of own color functions should be simple:

mycolorfun=Function[Blend[{Red,Green,Blue},#]]

this will change an existing colorfunction:

newfun = ColorData["Rainbow"] /.
RGBColor[0.513417`, 0.72992`, 0.440682`] -> RGBColor[1, 1, 1]

since there is additional information used for the formatting that is
not updated within the ColorFunction-Object, you might want to extract
the pure functions and work with only those:

newfun = ColorData["Rainbow"] /.
RGBColor[0.513417`, 0.72992`, 0.440682`] -> RGBColor[1, 1, 1]

hth,

albert

magma

Oct 3, 2008, 6:41:44 AM10/3/08
to
Use Blend
The second definition is probably what you are looking for.

Blend[{Subscript[col, 1],Subscript[col, 2],Subscript[col, 3],\
\[Ellipsis]},x]
linearly interpolates between colors Subscript[col, i] as x varies \
from 0 to 1.

Jean-Marc Gulliet

Oct 3, 2008, 6:42:27 AM10/3/08
to
Tyler wrote:

Hi Tyler,

Not sure whether this is what you are looking for, but the following
thread, "Gradient fill as Background for Plot", might be of some help:

HTH (and that you won't have to hurt yourself anymore :-)]
-- Jean-Marc

Szabolcs Horvát

Oct 3, 2008, 6:42:38 AM10/3/08
to

Some examples:

cbar[cfun_] :=
DensityPlot[x, {x, 0, 1}, {y, 0, 1}, AspectRatio -> 1/7,
Frame -> False, ColorFunction -> cfun]

cbar["Rainbow"]

cbar[Blend[{Red, Green, Blue}, #] &]

Built-in gradient transformed with a power function:

cbar[ColorData["Rainbow"][#^4] &]

Tyler

Oct 4, 2008, 6:16:37 AM10/4/08
to
Thanks for the tips everyone! Looks like I have a full weekend ahead
playing with ColorFunctions and Blend....

Cheers,

t.

PS - I never thought to try FullForm on ColorData...nice trick :)

Tyler

Oct 5, 2008, 2:23:04 AM10/5/08
to
Thanks for the tips everyone! Looks like I have a full weekend ahead
playing with ColorFunctions and Blend....

Cheers,

t.

PS - I never thought to try FullForm on ColorData...nice trick :)

On Oct 3, 6:42 am, Szabolcs Horv=E1t <szhor...@gmail.com> wrote:

Tyler

Oct 5, 2008, 5:37:25 AM10/5/08
to
Thanks for the tips everyone! Looks like I have a full weekend ahead
playing with ColorFunctions and Blend....

Cheers,

t.

PS - I never thought to try FullForm on ColorData...nice trick :)

On Oct 3, 6:42 am, Szabolcs Horv=E1t <szhor...@gmail.com> wrote: