# Plotting slices of 3D surface

**URL:** <https://community.wolfram.com/t/plotting-slices-of-3d-surface/7061>\
**Category:** Questions\
**Tags:** graphics-and-visualization\
**Created:** [October 29, 2015, 12:35pm UTC](https://community.wolfram.com/t/plotting-slices-of-3d-surface/7061 "2015-10-29T12:35:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![aymane1000](https://avatars.discourse-cdn.com/v4/letter/a/96bed5/32.png) [@aymane1000](https://community.wolfram.com/u/aymane1000)\
**Post date:** [October 29, 2015, 12:35pm UTC](https://community.wolfram.com/t/plotting-slices-of-3d-surface/7061/1 "2015-10-29T12:35:18Z")

</div>

i wanna draw the fuction w(x,y)=cosx.siny in wolfram mathematica 10 and also draw the cuts which are parallel to the x-axis in a Manipulate environment in which y from -? to ? is varied. Do the same with reversed roles of x and y. use the option Axes ? {False, True} and enter a range of values explicitly [-1,1]

Thanks in advance

---

<div class="post-metadata">

**Author:** ![murray](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/murray/32/39879_2.png) [@murray](https://community.wolfram.com/u/murray)\
**Post date:** [October 29, 2015, 3:20pm UTC](https://community.wolfram.com/t/plotting-slices-of-3d-surface/7061/2 "2015-10-29T15:20:05Z")

</div>

Try breaking the problem up into simpler things.

(1) You need the correct syntax for a _Mathematica_ function:

```
w[x_,y_] := Cos[x] Sin[y]

```

[I’m presuming that your ambiguous expression cosx.siny means, in traditional math notation, (cos x) (sin y) rather than cos(x sin y).]

(2) Then a 3d plot would be given by:

```
 Plot3D[w[x, y], {x, -3 Pi/2, 3 Pi/2}, {y, -3 Pi/2, 3 Pi/2}]

```

(3) Add one specific y = constant, say y = 2.25, slice by using a corresponding value for option Mesh:

```
yTrace = Plot3D[w[x, y], {x, -3 Pi/2, 3 Pi/2}, {y, -3 Pi/2, 3 Pi/2}, 
   Mesh -> {{-5}, {{2.25, Directive[Thick, Red]}}}, 
   PlotStyle -> LightBlue, AxesLabel -> {x, y, z}]

```

 ![ySplice2.png](https://global.discourse-cdn.com/wolfram/original/2X/f/f8e1eaee83e5eda956fe0cef30c39f478166a99e.png)

(The first entry {-5} in the value of Mesh is a “dummy” value for an x-slice, chosen to be outside the specified x-domain.)

(4) Do a similar thing for one specific x = constant slice.

(5) Construct a Manipulate in a simple form just for varying the constant in, say, y = constant.

(6) Repeat (5) for x = constant.

(7) Put the results of (5) and (6) together.

_Note:_ You’ll find this sort of thing already created in the Wolfram Demonstration:  
[http://demonstrations.wolfram.com/CrossSectionsOfGraphsOfFunctionsOfTwoVariables/](http://demonstrations.wolfram.com/CrossSectionsOfGraphsOfFunctionsOfTwoVariables/)

(I found that Demonstration simply by Googling “mathematica slice 3d plot”.)

If you want to show the plane y = constant that makes the slice, combine the Plot3D with an appropriate ContourPlot3D:

```
 ySlice = ContourPlot3D[y == 2.25, {x, -3 Pi/2, 3 Pi/2}, {y, -3 Pi/2, 3 Pi/2}, {z, -1, 1}, 
                   ContourStyle -> Opacity[0.5, Lighter@Green], Mesh -> None]

```

Then combine yTrace with ySlice using Show:  
Show[{yTrace, ySlice}]

 ![both.png](https://global.discourse-cdn.com/wolfram/original/3X/1/3/1324babdea4251b7284d0d122e0146a6fcb4a6f6.png)

Note that I made no serious attempt to make the 3d graphics look as clear and appealing as possible. Doing such things takes a _lot_ of work (at least for me).  
[1]: [http://community.wolfram.com//c/portal/getImageAttachment?filename=ySplice2.png&userId=50264](http://community.wolfram.com//c/portal/getImageAttachment?filename=ySplice2.png&userId=50264)  
[2]: [http://community.wolfram.com//c/portal/getImageAttachment?filename=both.png&userId=50264](http://community.wolfram.com//c/portal/getImageAttachment?filename=both.png&userId=50264)

---

<div class="post-metadata">

**Author:** ![seanc](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/seanc/32/34005_2.png) [@seanc](https://community.wolfram.com/u/seanc)\
**Post date:** [October 29, 2015, 3:23pm UTC](https://community.wolfram.com/t/plotting-slices-of-3d-surface/7061/3 "2015-10-29T15:23:01Z")

</div>

What code do you have already?

First, try making the plot of w(x,y)=cosx.siny.

Then separately try to make the plot of your cuts for several different values.

---

<div class="post-metadata">

**Author:** ![murray](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/murray/32/39879_2.png) [@murray](https://community.wolfram.com/u/murray)\
**Post date:** [October 29, 2015, 4:28pm UTC](https://community.wolfram.com/t/plotting-slices-of-3d-surface/7061/4 "2015-10-29T16:28:03Z")

</div>

Somebody who has the power, please change the subject of this thread from “wolfram mathematica 10” to something that’s actually informative and specific, such as “Plotting slices of 3D surface” or “Adding slices to plot of function of 2 variables”.

---

<div class="post-metadata">

**Author:** ![aymane1000](https://avatars.discourse-cdn.com/v4/letter/a/96bed5/32.png) [@aymane1000](https://community.wolfram.com/u/aymane1000)\
**Post date:** [October 30, 2015, 3:48pm UTC](https://community.wolfram.com/t/plotting-slices-of-3d-surface/7061/5 "2015-10-30T15:48:52Z")

</div>

thank u so much but still i tried to draw it but this error[Options expected (instead of Null) beyond position 3 in Plot3D[w[x,y],{x,-((3 [Pi])/2),(3 [Pi])/2},{y,-((3 [Pi])/2),(3 [Pi])/2},Mesh-\>{{-5},{{2.25,Directive[Thick,Red]}}},PlotStyle-\>LightBlue,Null,AxesLabel-\>{x,y,z}]. An option must be a rule or a list of rules. \>\>] appears sorry for bothering u because i m just a beginner and i study in german …so complicated ..thanks anyway

---

<div class="post-metadata">

**Author:** ![murray](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/murray/32/39879_2.png) [@murray](https://community.wolfram.com/u/murray)\
**Post date:** [October 30, 2015, 4:29pm UTC](https://community.wolfram.com/t/plotting-slices-of-3d-surface/7061/6 "2015-10-30T16:29:50Z")

</div>

Sorry, in the Plot3D expression, there was an extra comma just before “AxesLabel”. I’ve edited the code in my long post to remove it. And I directly copied from there into a _Mathematica_ notebook where I executed it without error.
