Elementary Graphing Commands

2+3/4

(2+3)/4

{a,2,3}

Basic 2-dimensional Plots

"Plot" is the basic command to graph a function. Its argument must include the function, here "Sin[x]", and a list, here "{x,-Pi,Pi}", listing the independent variable and the domain.

Plot[Sin[x],{x,-Pi,Pi}]

Plot[{Cos[x],Sin[x]},{x,-Pi,Pi}]

"Plot" has dozens of options, most of them in the form "option->setting". The command below results in a blue graph.

Plot[Sin[x],{x,-Pi,Pi},
	PlotStyle->Green]

Plot[Sin[x],{x,-Pi,Pi},PlotStyle->{AbsoluteThickness[4],Blue},AxesLabel->{x,y},
	PlotRange->{-1.5,1.5}]

You can find out about possible options for a command - not only "Plot" - by using "Options":

Options[Plot]

Plot[{Sin[x],Cos[x]},{x,-π,π},PlotStyle->{{AbsoluteThickness[2],Dotted,Blue},{AbsoluteThickness[3],Dashed,Black}},AxesLabel->{x,y},PlotRange->{-1.5`,1.5`}]

"ParametricPlot" graphs a parametrized function of the form (x(t),y(t)). In the example below, x=Sin[t],y=Cos[t] parametrizes the unit circle.

ParametricPlot[{Sin[t],Cos[t]},{t,0,2 π}]

"AspectRatio" sets the ratio of the height of the picture over the width of the picture. Its default for most 2-dimensional plots is:

1./GoldenRatio

ParametricPlot[{Sin[t],Cos[t]},{t,0,2 π},AspectRatio->1,PlotStyle->GrayLevel[0.7]]

ParametricPlot[{Sin[t],Cos[t]},{t,0,2 π},PlotStyle->GrayLevel[0.7]]

Setting "AspectRatio->Automatic" results in a plot, which respects the units on both axes. In the plot below the picture is three times as wide as it is tall.

Plot[Sin[x],{x,-3,3},AspectRatio->1/2]

ContourPlot[(x^2)+(y^2)==1,{x,-1,1},{y,-1,1}]

We give the plot below a name, here "p1", since we want to use it later on.

p1=ContourPlot[(x^2)-(y^2)==-1,{x,-3,3},{y,-3,3},AspectRatio->1]

p0=Plot[{-x,x},{x,-2,2},PlotStyle->{{Green,Dashing[{0.015`,0.015`}]}}]

"Show" is used to combine several "Graphics":

Show[p0,p1,AspectRatio->1,AxesLabel->{x,y}]

Show[p1,p0,AxesLabel->{x,y}]

Basic 3-Dimensional Plots

"Plot3D" is the basic command to graph a function of the form z=f(x,y).

Plot3D[(x^2)+(y^2),{x,-2,2},{y,-2,2}]

Options[Plot3D]

You can, f.i., change the viewpoint by evoking the option "ViewPoint".
On most platforms, the 'Input' Menu has a submenu '3DViewPointSelector' which automatically computes the input to "ViewPoint".

Plot3D[(x^2)+(y^2),{x,-2,2},{y,-2,2},ViewPoint->{6.696,-0.907,1.833}]

"BoxRatios" corresponds for 3D plots to "AspectRatio".

Plot3D[(x^2)+(y^2),{x,-2,2},{y,-2,2},BoxRatios->{1,2,3},AxesLabel->{x,y,z}]

"ParametricPlot3D" works similar to "ParamentricPlot". It can be used to plot curves (one parameter) and to plot surfaces (2 parameters).

ParametricPlot3D[{Sin[t],Cos[t],t},{t,0,4 π},BoxRatios->{3,3,1},AxesLabel->{"x(t)","y(t)","z(t)"}]

ParametricPlot3D[{Cos[s] Sin[t],Sin[s] Sin[t],Cos[t]},{t,(π/6),π},{s,0,2 π},AxesLabel->{"x(s,t)","y(s,t)","z(s,t)"}]

Other visualizations for 3D functions are "ContourPlot" and "DensityPlot".

ContourPlot[(x^2)+(y^2),{x,-2,2},{y,-2,2}]

DensityPlot[(x^2)+(y^2),{x,-2,2},{y,-2,2}]

Example: An Animation

Animate[Plot[k Sin[k x],{x,0,2Pi},PlotRange->{-10,10}],{k,1,10}]

Manipulate[Plot[Sin[k x],{x,0,2Pi}],{k,1,10,1}]

Try It Yourself !

1. Graph 1/x  for x between -1 and 2.

2. Graph arctan(2t) for t between -5 and 5. Make the graph thick and color it in green.

3. Graph the ellipse (x^2)+2(y^2)-x y =7.  Adjust the display so that the picture of the ellipse is not distorted.

4. Graph the paraboloid z=(x^2)+(y^2.)

5. Graph the ellipsoid (x^2)+(y^2)+2(z^2)=4.