       Re: Problems with defintion of a ContourFunction

• To: mathgroup at christensen.cybernetics.net
• Subject: [mg1578] Re: [mg1557] Problems with defintion of a ContourFunction
• From: twj (Tom Wickham-Jones)
• Date: Sat, 1 Jul 1995 03:18:08 -0400

```
Martina Giarre writes:

>I have some problems in defining a ContourFunction. I cannot
>specify a color for a certain z-value in a ListContourPlot.

The values passed to the ColorFunction are scaled from the values

of the contour lines and the minimum and maximum z values of the

PlotRange.   The lowest value is the midpoint between the lowest
contour and z_{min; this gets scaled to 0.  The highest value is

the midpoint between the highest contour and z_max; this gets scaled

to 1.   The intermediate points are the midpoints between the appropriate

contour lines.  All the values are scaled with a linear function
so that the minimum  and maximum values are 0 and 1 respectively.
This can be represented by the Mathematca function where vals are

the contour lines and z1 and z2 are respectively the minimum and maximum

z values of the PlotRange.

ColorFunctionValues[vals_List, {z1_, z2_}] :=
Module[{p1, p2, pf, res},
p1 = (z1 + First[vals])/2. ;
p2 = (z2 + Last[vals])/2. ;
pf = p2 - p1 ;
res =
Table[
((Part[vals, i] + Part[vals, i+1])/2. - p1)/pf,
{i,Length[vals] - 1}] ;
Join[{0}, res, {1}]
]

In the example given:

>test = Transpose[{{1,2,3,4,5,6},{1,2,3,4,5,6},
>		{1,2,3,4,5,6},{1,2,3,4,5,6},
>		{1,2,3,4,5,6},{1,2,3,4,5,6}}];
>
>g = {1,2,3,4,5,6};
>tc = Table[{Hue[d]},{d,0.4,1,0.1}];
>c[f_]:=While[f<=1,Hue[0.9]]
>ListContourPlot[test,	PlotRange->{1,6},

>			Contours->g,

>			ContourStyle->tc,
>			ContourLines->True,
>			ColorFunction->c];

The c[f_] function must be wrong,  this has a While, changing this
to an If defines a color function that will always return Hue[0.9],
which also probably is wrong since generally the levels

Here is a different color function, (this one prints out the argument),
and then uses the argument to pick out a color from a list.

In:= c[f_] := (Print[f]; Part[ tc, Floor[6f +1.5],1])

In:= test = Transpose[{{1,2,3,4,5,6},{1,2,3,4,5,6},
{1,2,3,4,5,6},{1,2,3,4,5,6},
{1,2,3,4,5,6},{1,2,3,4,5,6}}];

In:= g = {1,2,3,4,5,6};

In:= tc = Table[{Hue[d]},{d,0.4,1,0.1}];

In:= ListContourPlot[test,  PlotRange->{1,6},

Contours->g,

ContourStyle->tc,
ContourLines->True,
ColorFunction->c];
0.1
0.3
0.5
0.7
0.9
0.
1.

which prints out the values past to the ColorFunction.
Now using the ColorFunctionValues function defined above
these values can be confirmed.

In:= ColorFunctionValues[vals_List, {z1_, z2_}] :=
Module[{p1, p2, pf, res},
p1 = (z1 + First[vals])/2. ;
p2 = (z2 + Last[vals])/2. ;
pf = p2 - p1 ;
res =
Table[
((Part[vals, i] + Part[vals, i+1])/2. - p1)/pf,
{i,Length[vals] - 1}] ;
Join[{0}, res, {1}]
]

In:= ColorFunctionValues[ g, {1,6}]

Out= {0, 0.1, 0.3, 0.5, 0.7, 0.9, 1}

Tom Wickham-Jones
WRI

```

• Prev by Date: Re: roots
• Next by Date: Help !! Subrutine for founding complex roots of a polinomy expression.
• Previous by thread: Re: roots
• Next by thread: Re: Problems with defintion of a ContourFunction