Mathematica 9 is now available
Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1995

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: color function for ContourPlot

  • To: mathgroup at
  • Subject: [mg1118] Re: color function for ContourPlot
  • From: rubin at (Paul A. Rubin)
  • Date: Mon, 15 May 1995 01:41:45 -0400

In article <3os71e$r7q at>,
   Fredo Sartori <sartori at> wrote:
->Producing a contor plot using ColorFunction->Hue gives the same color for 
->lowest as for the highest regions in the plot whic his rather 
->same problem is encountered when making a surface graphics with 
->ColorFunction->Hue. In the latter case creating an module like the 
->solves the problem:
->	rainbowColor[array_, label_] :=
->   		Module[
->          		{min, max, length},
->          		min = Min[array];
->          		max = Max[array];
->          		length = Length[array[[1]]];
->          		ListPlot3D[array,
->                           		{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,

How about this:

rainbowContour[ array_, label_, hscale_:1 ] :=
    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 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

  • Prev by Date: Re: Looking for MMA Code/Modern Diff. Geom./Alfred Gray
  • Next by Date: Re: Help: General Protection Fault caused by Mathematica for Windows
  • Previous by thread: Re: color function for ContourPlot
  • Next by thread: Looking for MMA Code/Modern Diff. Geom./Alfred Gray