Function Repository Resource:

SectionPlot3D

Source Notebook

Plot a surface together with various types of sections of the surface

Contributed by: Dennis M Schneider

ResourceFunction["SectionPlot3D"][f,{x,xmin,xmax},{y,ymin,ymax},opts]

generate a three-dimensional plot of f as a function of x and y highlighting sections specified by opts.

ResourceFunction["SectionPlot3D"][f,{x,xmin,xmax},{y,ymin,ymax},{{gx,gy},},{t,tmin,tmax}}]

plots the section of the surface determined by the generalized cylinders described parametrically by {{gx,gy},},{t,tmin,tmax}.

Details and Options

Generalized cylinders defined by the parametric function g need not be circular.
Generalized cylinders are defined as in MathWorld.
Sections defined in opts must include options values for at least one of the following: "XSection", "YSection", "ZSection", "VSection", or "OSection".
ResourceFunction["SectionPlot3D"] has the same options as Plot3D with the following additions and changes:
"ColorFunctionSection"Automaticspecifies the color function(s) for the section
"ColorFunctionSurface"Automaticspecifies the color function(s) for the surface
"CylinderBase"Automaticdetermines the z-value to which cylinders are projected
"CylinderRange"Automaticdetermines the range of the cylinder
"CylinderStyle"Opacity[0.4]specifies style for the cylinder; it ignores color specifications.
"DrawCylinder"Truewhether to draw the cylinder
"DrawPoint"{}a list of points to be included in the plot
"DrawPointStyle"{{Red,PointSize[Large]}}styles to be applied to the points specified with the option "DrawPoint"
"OSection"{}draws an oblique section determined by functions of the form z=f[x],z=g[y], or z=h[x,y]
"OSectionStyle"{{Red,Tube[.02]}}styles to be applied to the oblique sections
"PlotPointsSection"75specifies how many initial sample points to use in plotting sections
PlotStyleOpacity[0.7]graphics directive for the style for each surface
"SectionStyle"{{Red,Tube[.02]}}styles to be applied to sections defined parametrically by {gx,gy}
"Surface"Truewhether to return the surface in the plot
"VSection"{}draws vertical section(s) for a function or list of functions of the form y=f[x] or x=g[y]
"VSectionStyle"{{Red,Tube[.02]}}styles to be applied to the vertical sections
"XSection"{}draws vertical sections parallel to the yz-plane determined by the value or list of values of x
"XSectionStyle"{{Red,Tube[.02]}}styles to be applied to the x-sections
"YSection"{}draws vertical sections parallel to the xz-plane determined by the value or list of values of y
"YSectionStyle"{{Red,Tube[.02]}}styles to be applied to the y-sections
"ZSection"{}draws horizontal sections parallel to the xy-plane determined by the value or list of values of z
"ZSectionStyle"{{Red,Tube[.02]}}styles to be applied to the z-sections

Examples

Basic Examples (1) 

Plot a surface with a circular section:

In[1]:=
ResourceFunction["SectionPlot3D"][
 Sin[\[Pi] x y], {x, -1, 1}, {y, -1, 1}, {Cos[t], Sin[t]}, {t, 0, 2 \[Pi]}]
Out[1]=

Scope (3) 

Plot a surface with all possible plane sections:

In[2]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/4b23abc9-4e34-4e3e-90db-375a3f3d7598"]
Out[2]=

Plot a surface with both a plane section and a parametrically-defined section:

In[3]:=
ResourceFunction["SectionPlot3D"][
 Sin[\[Pi] x y], {x, -1, 1}, {y, -1, 1}, {Cos[t], Sin[t]}, {t, 0, 2 \[Pi]}, "ZSection" -> 1/2, Mesh -> None]
Out[3]=

Plot two surfaces with their intersection illustrated with sections:

In[4]:=
ResourceFunction[
 "SectionPlot3D"][{1 - x^2 - y^2, x^2 - y^2}, {x, -1, 1}, {y, -1, 1}, "CylinderStyle" -> Opacity[.9], BoxRatios -> Automatic, "XSection" -> {-1/Sqrt[2], 1/Sqrt[2]}, PlotStyle -> {Opacity[.8], Opacity[1]}]
Out[4]=

Options (29) 

ColorFunctionSection (2) 

Set a style for the sections:

In[5]:=
ResourceFunction["SectionPlot3D"][
 x^2 - y^2, {x, -1, 1}, {y, -1, 1}, {{Cos[t], Sin[t]}, 1/2 {Cos[t], Sin[t]}}, {t, 0, 2 \[Pi]}, "ColorFunctionSection" -> Function[{x, y, z, t}, GrayLevel[t]], BoxRatios -> Automatic]
Out[5]=

Set a different style for each section:

In[6]:=
ResourceFunction["SectionPlot3D"][
 x^2 - y^2, {x, -1, 1}, {y, -1, 1}, {{Cos[t], Sin[t]}, 1/2 {Cos[t], Sin[t]}}, {t, 0, 2 \[Pi]}, "ColorFunctionSection" -> {Function[{x, y, z, t}, Hue[t/2]], Function[{x, y, z, t}, Hue[t]]}, BoxRatios -> Automatic]
Out[6]=

ColorFunctionSurface (2) 

Set a style for the surface:

In[7]:=
ResourceFunction["SectionPlot3D"][
 x^2 - y^2, {x, -1, 1}, {y, -1, 1}, {{Cos[t], Sin[t]}, 1/4 {Cos[t], Sin[t]}}, {t, 0, 2 \[Pi]}, "ColorFunctionSurface" -> Function[{x, y, z}, Hue[z]]]
Out[7]=

Set a color function for both the surface and the sections:

In[8]:=
ResourceFunction["SectionPlot3D"][
 x^2 - y^2, {x, -1, 1}, {y, -1, 1}, {{Cos[t], Sin[t]}, 1/4 {Cos[t], Sin[t]}}, {t, 0, 2 \[Pi]},
 "ColorFunctionSurface" -> Function[{x, y, z}, Hue[z]], "ColorFunctionSection" -> Function[{x, y, z}, GrayLevel[z]]]
Out[8]=

CylinderBase (1) 

Set where to place the base of the cylinder:

In[9]:=
ResourceFunction["SectionPlot3D"][
 Sin[x^2 - y^2], {x, -2, 2}, {y, -2, 2}, {2 Cos[t], Sin[t]}, {t, 0, 2 \[Pi]}, "CylinderBase" -> -2, BoxRatios -> Automatic]
Out[9]=

CylinderRange (5) 

Set the cylinder to be drawn from the top of the bounding box down to the surface:

In[10]:=
ResourceFunction["SectionPlot3D"][
 x^2 - y^2, {x, -1, 1}, {y, -1, 1}, {Cos[t], Sin[t]}, {t, 0, 2 \[Pi]},
  "CylinderRange" -> Reverse]
Out[10]=

Draw the cylinder both above and below the surface:

In[11]:=
ResourceFunction["SectionPlot3D"][
 x^2 - y^2, {x, -1, 1}, {y, -1, 1}, {Cos[t], Sin[t]}, {t, 0, 2 \[Pi]},
  "CylinderRange" -> {-2, 2}, BoxRatios -> Automatic]
Out[11]=

Draw the cylinder to full height:

In[12]:=
ResourceFunction["SectionPlot3D"][
 x^2 - y^2, {x, -1, 1}, {y, -1, 1}, {Cos[t], Sin[t]}, {t, 0, 2 \[Pi]},
  "CylinderRange" -> All, BoxRatios -> Automatic]
Out[12]=

Draw a cylinder from a base of -2 to the surface (this is the same as setting "CylinderBase" -2):

In[13]:=
ResourceFunction["SectionPlot3D"][
 x^2 - y^2, {x, -1, 1}, {y, -1, 1}, {Cos[t], Sin[t]}, {t, 0, 2 \[Pi]},
  "CylinderRange" -> {-2, Automatic}, BoxRatios -> Automatic]
Out[13]=

"CylinderRange" takes precedence over "CylinderBase":

In[14]:=
ResourceFunction["SectionPlot3D"][
 x^2 - y^2, {x, -1, 1}, {y, -1, 1}, {Cos[t], Sin[t]}, {t, 0, 2 \[Pi]},
  "CylinderRange" -> All, "CylinderBase" -> -2, BoxRatios -> Automatic]
Out[14]=

CylinderStyle (1) 

Apply a style to the cylinder:

In[15]:=
ResourceFunction["SectionPlot3D"][
 Sin[x^2 - y^2], {x, -2, 2}, {y, -2, 2}, {2 Cos[t], Sin[t]}, {t, 0, 2 \[Pi]}, "CylinderStyle" -> Opacity[1]]
Out[15]=

DrawCylinder (1) 

Suppress the plot of the cylinder:

In[16]:=
ResourceFunction["SectionPlot3D"][
 Sin[x^2 - y^2], {x, -2, 2}, {y, -2, 2}, {2 Cos[t], Sin[t]}, {t, 0, 2 \[Pi]}, "DrawCylinder" -> False]
Out[16]=

DrawPoint and DrawPointStyle (1) 

Add points and styles to the points:

In[17]:=
ResourceFunction["SectionPlot3D"][
 x^2 - y^2, {x, -1, 1}, {y, -1, 1}, {Cos[t], Sin[t]}, {t, 0, 2 \[Pi]},
  "DrawPoint" -> {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {1/2, 1/2, 3}}, "DrawPointStyle" -> {{PointSize[.05], Red}, {PointSize[.05], Orange}, {PointSize[.06], Green}, {PointSize[.06], Blue}, {PointSize[.08], Magenta}}]
Out[17]=

OSection (1) 

Add oblique sections:

In[18]:=
ResourceFunction["SectionPlot3D"][-x^2 - y^2, {x, -1, 1}, {y, -1, 1}, "OSection" -> {-(x/3), -(x/4) + y/8 - 1/2}, BoxRatios -> Automatic, PlotRange -> All]
Out[18]=

OSectionStyle (1) 

Add styles:

In[19]:=
ResourceFunction["SectionPlot3D"][-x^2 - y^2, {x, -1, 1}, {y, -1, 1}, "OSection" -> {-(x/3), -(x/4) + y/8 - 1/2}, "OSectionStyle" -> {Red, {Tube[.03], Blue}}, BoxRatios -> Automatic, PlotRange -> All]
Out[19]=

PlotPointsSection (1) 

Change the number of points used to plot the section(s). Since the Wolfram Language’s plotting commands use adaptive procedures to determine how many points to actually plot, we must turn off this feature by setting the option MaxRecursion:

In[20]:=
ResourceFunction["SectionPlot3D"][
 x^2 - y^4, {x, -1, 1}, {y, -1, 1}, {1/(1 + t^2) Cos[5 t], 1/(1 + t^2) Sin[5 t]}, {t, 0, 2 \[Pi]}, BoxRatios -> Automatic, PlotStyle -> Opacity[.3], Mesh -> None, "PlotPointsSection" -> 25, MaxRecursion -> 0]
Out[20]=

PlotStyle (1) 

Apply a style to the surface:

In[21]:=
ResourceFunction[
 "SectionPlot3D"][x^3, {x, -1, 1}, {y, -1, 1}, {t, t^2}, {t, -1, 1}, BoxRatios -> Automatic, PlotStyle -> {{Opacity[.8], Orange}}, Mesh -> None]
Out[21]=

SectionStyle (1) 

Apply a style to the section:

In[22]:=
ResourceFunction["SectionPlot3D"][
 x^2 - y^2, {x, -1, 1}, {y, -1, 1}, {Cos[t], Sin[t]}, {t, 0, 2 \[Pi]},
  "SectionStyle" -> {{Tube[.03], Magenta}}]
Out[22]=

Surface (1) 

Suppress the plot of the surface:

In[23]:=
GraphicsRow[{ResourceFunction["SectionPlot3D"][
   Sin[x^2 - y^2], {x, -2, 2}, {y, -2, 2}, {2 Cos[t], Sin[t]}, {t, 0, 2 \[Pi]}, "CylinderStyle" -> Opacity[1]], ResourceFunction["SectionPlot3D"][
   Sin[x^2 - y^2], {x, -2, 2}, {y, -2, 2}, {2 Cos[t], Sin[t]}, {t, 0, 2 \[Pi]}, "CylinderStyle" -> Opacity[1], "Surface" -> False]}, ImageSize -> Full]
Out[23]=

VSection (2) 

Add vertical sections:

In[24]:=
ResourceFunction["SectionPlot3D"][
 2 Sin[y] Cos[x], {x, -3, 3}, {y, -3, 3}, "VSection" -> {x/2, 2 x}]
Out[24]=

VSections can be any function of x or y:

In[25]:=
ResourceFunction["SectionPlot3D"][
 2 Sin[y] Cos[x], {x, -3, 3}, {y, -3, 3}, "VSection" -> {x == Sin[2 y], y^2}, "DrawCylinder" -> False]
Out[25]=

VSectionStyle (1) 

Set a style:

In[26]:=
ResourceFunction["SectionPlot3D"][
 2 Sin[y] Cos[x], {x, -3, 3}, {y, -3, 3}, "VSection" -> {Sin[2 y], x^3}, "VSectionStyle" -> {{Red, Tube[.05]}, {Blue, Tube[.05]}}, "DrawCylinder" -> False]
Out[26]=

XSection (1) 

Add x-sections:

In[27]:=
ResourceFunction["SectionPlot3D"][
 2 Sin[y] Cos[x], {x, -3, 3}, {y, -3, 3}, "XSection" -> {-1, 1/2}]
Out[27]=

XSectionStyle (2) 

Assign a style to the x-sections:

In[28]:=
ResourceFunction["SectionPlot3D"][
 2 Sin[y] Cos[x], {x, -3, 3}, {y, -3, 3}, "XSection" -> {-1, 1/2}, "XSectionStyle" -> {{Tube[.03], Blue}, {Tube[.06], Red}}]
Out[28]=

Plot several sections and suppress the plot of the surface:

In[29]:=
ResourceFunction["SectionPlot3D"][-x^2 - y^2, {x, -1, 1}, {y, -1, 1}, "XSection" -> {-1, -(1/2), 0, 1/2, 1}, "Surface" -> False, "XSectionStyle" -> Table[Hue[j], {j, 0, 1, 1/5}]]
Out[29]=

YSection (1) 

Add y-sections:

In[30]:=
ResourceFunction["SectionPlot3D"][-x^6 - y^2, {x, -1, 1}, {y, -1, 1}, "YSection" -> {-1/2, 0, 1/2}]
Out[30]=

YSectionStyle (1) 

Set a style for the y-sections:

In[31]:=
ResourceFunction["SectionPlot3D"][-x^6 - y^2, {x, -1, 1}, {y, -1, 1}, "YSection" -> {-1/2, 0, 1/2}, "YSectionStyle" -> {Purple, Pink, Green}]
Out[31]=

ZSection (1) 

Add z-sections:

In[32]:=
ResourceFunction["SectionPlot3D"][-x^2 - y^2, {x, -1, 1}, {y, -1, 1}, "ZSection" -> {-(1/2), -1}, Mesh -> False, BoxRatios -> Automatic]
Out[32]=

ZSectionStyle (1) 

Set a style for z-sections:

In[33]:=
ResourceFunction["SectionPlot3D"][-x^2 - y^2, {x, -1, 1}, {y, -1, 1}, "ZSection" -> {-(1/2), -1}, "ZSectionStyle" -> {{Green, Tube[.02]}, {Blue, Tube[.04]}}, BoxRatios -> Automatic]
Out[33]=

Possible Issues (6) 

SectionPlot3D only allows one color function:

In[34]:=
ResourceFunction[
 "SectionPlot3D"][{Cos[\[Pi] x y], Sin[\[Pi] x y]}, {x, -1, 1}, {y, -1, 1}, {Cos[t], Sin[t]}, {t, 0, 2 \[Pi]}, "ColorFunctionSurface" -> {Red, Green}]
Out[34]=

If one of the sections is outside the plot range, it is removed and a warning message is given:

In[35]:=
ResourceFunction["SectionPlot3D"][Sin[x^2 y], {x, -2, 2}, {y, -2, 2}, "XSection" -> {0, 3}, "YSection" -> 1]
Out[35]=

"CylinderStyle" does not allow a color directive:

In[36]:=
ResourceFunction["SectionPlot3D"][
 Sin[x^2 - y^2], {x, -2, 2}, {y, -2, 2}, {2 Cos[t], Sin[t]}, {t, 0, 2 \[Pi]}, "CylinderStyle" -> {{Opacity[1], Green}}]
Out[36]=

"SectionStyle" does not allow a opacity, dashing, or thickness directives. Opacity and dashing are dropped, and thickness is replaced by Tube:

In[37]:=
ResourceFunction["SectionPlot3D"][
 Sin[\[Pi] x y], {x, -1, 1}, {y, -1, 1}, {{Cos[t], Sin[t]}, {Cos[t], Sin[2 t]}}, {t, 0, 2 \[Pi]}, "SectionStyle" -> {{Opacity[1], Dashed, Thickness[.04], Green}}]
Out[37]=

"XSectionStyle", "YSectionStyle", "ZSectionStyle", "VSectionStyle", "OSectionStyle" do not accept opacity directives:

In[38]:=
ResourceFunction["SectionPlot3D"][Sin[x^2 y], {x, -2, 2}, {y, -2, 2}, "XSection" -> 1, "ZSection" -> -1/2, "ZSectionStyle" -> {{Blue, Opacity[1]}}]
Out[38]=

"VSection" must be set to one or more functions of x or y, but not both:

In[39]:=
ResourceFunction["SectionPlot3D"][Sin[x^2 y], {x, -2, 2}, {y, -2, 2}, "VSection" -> {x, -x, Cos[y], Sin[x y]}]
Out[39]=

Publisher

Dennis M Schneider

Version History

  • 1.0.0 – 10 October 2019

Related Resources

License Information