Re: color function for ContourPlot
- To: mathgroup at christensen.cybernetics.net
- Subject: [mg1118] Re: color function for ContourPlot
- From: rubin at msu.edu (Paul A. Rubin)
- Date: Mon, 15 May 1995 01:41:45 -0400
In article <3os71e$r7q at news0.cybernetics.net>,
Fredo Sartori <sartori at thetis.zedat.fu-berlin.de> wrote:
->Producing a contor plot using ColorFunction->Hue gives the same color for
the
->lowest as for the highest regions in the plot whic his rather
confusing.The
->same problem is encountered when making a surface graphics with
->ColorFunction->Hue. In the latter case creating an module like the
following
->one
->solves the problem:
->
-> rainbowColor[array_, label_] :=
-> Module[
-> {min, max, length},
-> min = Min[array];
-> max = Max[array];
-> length = Length[array[[1]]];
-> ListPlot3D[array,
->
Table[Hue[1./(1.1*(max-min))*array[[i]][[j]]],
-> {i, length-1},
-> {j, length-1}]
-> ]
-> ]
->
->
->Creating an analog module for the ConturGraphics fails:
->
-> rainbowContur[array_, label_] :=
-> Module[
-> {min, max, length},
-> min = Min[array];
-> max = Max[array];
-> length = Length[array[[1]]];
-> ListContourPlot[array,
-> Table[Hue[0.9/(max-min)*array[[i]][[j]]],
-> {i, length-1},
-> {j, length-1}]
-> ]
-> ]
->
->All that is produced is the following error message:
->
-> ListContourPlot::nonopt:
-> Options expected (instead of {<<36>>}) beyond position 1 in
-> ListContourPlot[{<<37>>}, {<<36>>}]. An option must be a rule
or a
-> list of rules.
->
->
->Any suggestions?
->
->Thanks in advance,
->
->Fredo
How about this:
rainbowContour[ array_, label_, hscale_:1 ] :=
ListContourPlot[
array,
ColorFunction -> (Hue[ #/hscale ]&),
PlotLabel -> label
] /; Positive[ hscale ]
The optional third parameter (hscale, defaults to 1) serves the same role
as the coefficient 1.1 in your rainbowColor function. ListContourPlot
feeds the ColorFunction arguments already scaled to the interval [0, 1], so
no additional scaling is necessary, other than to shrink the values a bit
(since Hue[0] and Hue[1] do indeed look the same to me).
By the way, in your rainbowColor function, you might want to subtract min
from array[[i, j]] in the table. Otherwise, it looks to me as though your
arguments to Hue might violate its domain (0 to 1).
Paul
**************************************************************************
* Paul A. Rubin Phone: (517) 432-3509 *
* Department of Management Fax: (517) 432-1111 *
* Eli Broad Graduate School of Management Net: RUBIN at MSU.EDU *
* Michigan State University *
* East Lansing, MI 48824-1122 (USA) *
**************************************************************************
Mathematicians are like Frenchmen: whenever you say something to them,
they translate it into their own language, and at once it is something
entirely different. J. W. v. GOETHE