Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2007

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

Search the Archive

Re: Does ColorFunction-> have different meanings to Plot3D and

  • To: mathgroup at smc.vnet.net
  • Subject: [mg83329] Re: Does ColorFunction-> have different meanings to Plot3D and
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Sat, 17 Nov 2007 05:32:28 -0500 (EST)
  • Organization: The Open University, Milton Keynes, UK
  • References: <fhjtbk$5n0$1@smc.vnet.net>

congruentialuminaire at yahoo.com wrote:

> I made a very simple 3D plot using a CF:
> 
> Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2},  ColorFunction -> (Hue[#]
> &)]
> 
> Then I made a contour plot of the identical function, also with CF:
> 
> ContourPLot[Sin[x + y^2], {x, -3, 3}, {y, -2, 2},  ColorFunction ->
> (Hue[#] &)]
> 
> Since I am using the identical function passed to the 2 plotting
> routines, I expect the color to show analogously. Specifically in the
> Plot3D, the color bands are straight and parallel to the y-axis. In
> the ContourPlot, the bands are curved with the contours.
> 
> Is it possible to make the CF correspond so that when both plots are
> shown, the color shows the correspondence between the plots (since the
> functions plotted are the same)? Alternatively, is there some other CF
> I can use with ContourPlot to accomplish the desired result?

The whale issue is about how many parameters are passed to ColorFunction 
by the different plotting functions. Plot3D passes the x, y, and z 
coordinates to ColorFunction (and Hue, accepting only one argument, 
defaults to x), so your code is equivalent to either

Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2}, ColorFunction -> Hue]

or

Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2},
  ColorFunction -> Function[{x, y, z}, Hue[x]]]

OTOH, ContourPlot passes only one value: the z value. So to get the same 
coloring scheme, you could use the following color function for Plot3D:

Plot3D[Sin[x + y^2], {x, -3, 3}, {y, -2, 2},
  ColorFunction -> Function[{x, y, z}, Hue[z]]]

which now matches with

ContourPlot[Sin[x + y^2], {x, -3, 3}, {y, -2, 2},
  ColorFunction -> (Hue[#] &)]

Regards,
-- 
Jean-Marc


  • Prev by Date: Re: Piecewise inside a Module or Block, I don't understand this behavior.
  • Next by Date: Re: Get list of function variables?
  • Previous by thread: Re: Does ColorFunction-> have different meanings to Plot3D and
  • Next by thread: Piecewise inside a Module or Block, I don't understand this behavior.