Introduction to Plotting in 3D
Author
Abby Brown
Title
Introduction to Plotting in 3D
Description
Outlines basic options useful for three-dimensional plots.
Category
Educational Materials
Keywords
Plot, Plot3D, 3D, graphs, surface, surfaces, 3D graphing, options, aspect ratio, proportions, AspectRatio, BoxRatios, PlotStyle, ClippingStyle, AxesOrigin, CT@TP, Computational Thinking, Torrey Pines High School, Beginner, Introduction, Abby Brown
URL
http://www.notebookarchive.org/2018-10-61jqsna/
DOI
https://notebookarchive.org/2018-10-61jqsna
Date Added
2018-10-13
Date Last Modified
2018-10-13
File Size
34.1 kilobytes
Supplements
Rights
Redistribution rights reserved



Introduction to Plotting in 3D
Introduction to Plotting in 3D
Read the notes below. Type and evaluate (shift-enter) the items listed with In[#]:= below.
You do not need to retype similar examples. Edit or copy/paste/edit past examples and evaluate.
You do not need to retype similar examples. Edit or copy/paste/edit past examples and evaluate.
3-Dimensional Graphing: Plot3D and Options
3-Dimensional Graphing: Plot3D and Options
Out[]=
We will graph this function: z= also known as f(x,y)=
y
x
x+1
y
x
x+1
Within the Plot3D command, list the function first (you do NOT need z = ). The function is followed by a comma and the domain you would like to graph in a list with curly braces { }. The domain list has the variable of the function first followed by the minimum and maximum values of the domain. You need a domain for both x and y for Plot3D. (A parametric curve in 3D may only need a domain for t.) Note that we use “E” for e in our code.
In[]:=
Plot3D[yE^x/(x+1),{x,-4,4},{y,-2,2}]
Use the option BoxRatios (instead of AspectRatio in 2D) to adjust the scale of the x-, y-, and z-axes. BoxRatiosAutomatic will make the scale for x, y, and z the same. If you put a list of numbers into BoxRatios, that sets the ratio of each axis. For example, BoxRatios{1,1,1} or just 1 makes it a cube and BoxRatios{1,1,2} is twice as tall as it is wide. Note with {1,1,2} the x and y are the same length, not the same scale.
Use the option BoxRatios (instead of AspectRatio in 2D) to adjust the scale of the x-, y-, and z-axes. BoxRatiosAutomatic will make the scale for x, y, and z the same. If you put a list of numbers into BoxRatios, that sets the ratio of each axis. For example, BoxRatios{1,1,1} or just 1 makes it a cube and BoxRatios{1,1,2} is twice as tall as it is wide. Note with {1,1,2} the x and y are the same length, not the same scale.
In[]:=
Plot3D[yE^x/(x+1),{x,-4,4},{y,-2,2},BoxRatiosAutomatic]
PlotRange will adjust the range on the z-axis of what is displayed for the graph.
PlotRange will adjust the range on the z-axis of what is displayed for the graph.
In[]:=
Plot3D[yE^x/(x+1),{x,-4,4},{y,-2,2},PlotRange{-4,4},BoxRatiosAutomatic]
A more detailed list of ranges will specify what you see in each direction.
A more detailed list of ranges will specify what you see in each direction.
In[]:=
Plot3D[yE^x/(x+1),{x,-4,4},{y,-2,2},PlotRange{{-2,2},{-10,10},{-4,4}},BoxRatiosAutomatic]
ImageSize adjusts the horizontal width of the plot in pixels. You may want to use a large size if you plan to copy/paste into another program (such as Word) for printing. Note: Printing in Mathematica does not always work very well. You can copy/paste into a new Mathematica notebook and be sure to use Print Preview...
ImageSize adjusts the horizontal width of the plot in pixels. You may want to use a large size if you plan to copy/paste into another program (such as Word) for printing. Note: Printing in Mathematica does not always work very well. You can copy/paste into a new Mathematica notebook and be sure to use Print Preview...
In[]:=
Plot3D[yE^x/(x+1),{x,-4,4},{y,-2,2},PlotRange{-4,4},BoxRatiosAutomatic,ImageSize500]
It is good to always label your axes. The first example gives basic labels. (See my 2D notes for styling.)
However, in 3D in Mathematica, the labels float in the middle of the axes and sometimes can get in the way of what you want to show or be distracting, so I often skip this in 3D.
It is good to always label your axes. The first example gives basic labels. (See my 2D notes for styling.)
However, in 3D in Mathematica, the labels float in the middle of the axes and sometimes can get in the way of what you want to show or be distracting, so I often skip this in 3D.
In[]:=
Plot3D[yE^x/(x+1),{x,-4,4},{y,-2,2},PlotRange{-4,4},BoxRatiosAutomatic,ImageSize500,AxesLabel{"x","y","z"}]
Often I remove the box (using Boxed) and set the axes to the corner we usually draw (using AxesEdge). Note that the origin is not necessarily where the axes meet. Axes→False will turn the axes off.
Often I remove the box (using Boxed) and set the axes to the corner we usually draw (using AxesEdge). Note that the origin is not necessarily where the axes meet. Axes→False will turn the axes off.
In[]:=
Plot3D[yE^x/(x+1),{x,-4,4},{y,-2,2},PlotRange{-4,4},BoxRatiosAutomatic,ImageSize500,BoxedFalse,AxesEdge{-1,-1}]
AxesOrigin will set the cross point of the axes and draw them inside the graphics box. However, they can float awkwardly within the image and I usually prefer them outside as above.
AxesOrigin will set the cross point of the axes and draw them inside the graphics box. However, they can float awkwardly within the image and I usually prefer them outside as above.
In[]:=
Plot3D[yE^x/(x+1),{x,-4,4},{y,-2,2},PlotRange{-4,4},BoxRatiosAutomatic,ImageSize500,BoxedFalse,AxesOrigin{0,0,0}]
Use Exclusions to remove asymptotes. Note the use of the double equal sign == for making an equation. You do not want to set x to equal -1. (Note: Not using AxesOrigin below.)
Use Exclusions to remove asymptotes. Note the use of the double equal sign == for making an equation. You do not want to set x to equal -1. (Note: Not using AxesOrigin below.)
In[]:=
Plot3D[yE^x/(x+1),{x,-4,4},{y,-2,2},PlotRange{-4,4},BoxRatiosAutomatic,ImageSize500,BoxedFalse,AxesEdge{-1,-1},Exclusions{x==-1}]
Use ClippingStyle to adjust what happens where the surface is cut off by the plot range.
Use ClippingStyle to adjust what happens where the surface is cut off by the plot range.
In[]:=
Plot3D[yE^x/(x+1),{x,-4,4},{y,-2,2},PlotRange{-4,4},BoxRatiosAutomatic,ImageSize500,BoxedFalse,AxesEdge{-1,-1},Exclusions{x==-1},ClippingStyleNone]
To style the surface of the function, use PlotStyle.
To style the surface of the function, use PlotStyle.
In[]:=
Plot3D[yE^x/(x+1),{x,-4,4},{y,-2,2},PlotRange{-4,4},BoxRatiosAutomatic,ImageSize500,BoxedFalse,AxesEdge{-1,-1},Exclusions{x==-1},ClippingStyleNone,PlotStyleBlue]
There are many configurations for Lighting in 3D. Sometimes using “Neutral” gives a nice effect.
There are many configurations for Lighting in 3D. Sometimes using “Neutral” gives a nice effect.
In[]:=
Plot3D[yE^x/(x+1),{x,-4,4},{y,-2,2},PlotStyleBlue,Lighting"Neutral"]
Note: The order of options does not matter. Options are listed after the domain and are separated by commas.
Note: The order of options does not matter. Options are listed after the domain and are separated by commas.
Try including the following options examples in your code.
In[]:=
MeshNone,MeshAutomatic,MeshShading{{Blue,Red},{Yellow,Green}}FaceGridsAll,FaceGridsNoneTicks{Range[-4,4]}Ticks{Range[-4,4,1/2],Range[-4,4,0.5],Range[-4,4,1]}Ticks{Range[-2Pi,2Pi,Pi/2],Range[-2,2],None}TicksNone
For more details on options for plots refer to the Documentation Center. For more with 2D plots, also see my additional notebook posted on my web site: www.abbymath.com/Mathematica/BasicOptionsForPlot.nb or “Basic Options for Plot” within www.notebookarchive.org.
For more details on options for plots refer to the Documentation Center. For more with 2D plots, also see my additional notebook posted on my web site: www.abbymath.com/Mathematica/BasicOptionsForPlot.nb or “Basic Options for Plot” within www.notebookarchive.org.
Abby Brown - www.abbymath.com - October 2015
Originally written to print as a photocopied handout for class.
Abby Brown - www.abbymath.com - October 2015
Originally written to print as a photocopied handout for class.
Originally written to print as a photocopied handout for class.


Cite this as: Abby Brown, "Introduction to Plotting in 3D" from the Notebook Archive (2018), https://notebookarchive.org/2018-10-61jqsna

Download

