0
$\begingroup$

I am given the following code in my notes:

  Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}, 
 PlotLabel -> "Plot of Sin[x y]",  AxesLabel -> {"x", "y"}, 
 ColorFunction -> (GrayLevel[#] &)]
Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}, 
 PlotLabel -> "Plot of Sin[x y]",  AxesLabel -> {"x", "y"}, 
 ColorFunction -> (GrayLevel[#1] &)]
Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}, 
 PlotLabel -> "Plot of Sin[x y]",  AxesLabel -> {"x", "y"}, 
 ColorFunction -> (GrayLevel[#2] &)]
Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}, 
 PlotLabel -> "Plot of Sin[x y]",  AxesLabel -> {"x", "y"}, 
 ColorFunction -> (GrayLevel[#3] &)]

I dont understand what the # values in the above context is. What values are being put in each case in the above code.

In general context the hash is called a slot and it is where the values are plugged in to the function

$\endgroup$
2
  • 1
    $\begingroup$ Yes... and the values passed to the ColorFunction are (internally) the value of the point being plotted. For functions such as Plot3D, the values are two-dimensional vectors, so #1 and #2 are the coordinates. $\endgroup$ May 22 at 19:19
  • $\begingroup$ And, so is #3. $\endgroup$
    – bbgodfrey
    May 22 at 19:28
1
$\begingroup$

Always good to play around and see what things actually do.

Simplifying your code to highlight the GrayLevel / Slot question:

Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3},ColorFunction -> (GrayLevel[#] &)]
Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3},ColorFunction -> (GrayLevel[#1] &)]
Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3},ColorFunction -> (GrayLevel[#2] &)]
Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3},ColorFunction -> (GrayLevel[#3] &)]

Which gives:

enter image description here

A little further investigation:

(GrayLevel[#] &) == (GrayLevel[#1] &)
True

So it doesn't look like you need both.

In the case of Plot3D, ColorFunction applies a color or in your cases, variation of gray to differences in the specified co-ordinates of the surface of the plot.

So, it looks like,

# or #1 applies it to the x axis, #2 to the y axis and #3 to the z axis.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.