More on Plots

We've seen 2-dimensional plots:

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

and 3-dimensional ones:

Plot3D[Sin[x y], {x, -Pi, Pi}, {y, -Pi, Pi}]

Note, however, that it was crucial that we knew how to express the function—plotted along the vertical (y or z axis)—in terms of the argument(s), and to precisely delineate the range of values for the arguments.

2D (Planar) Curves

Consider then:

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

This is a fairly simple graphics, the kind of which occurs quite often. However, it brings up the fact that this is not a single-valued function. To plot it in terms of Plot[] itself, we would have had to split it in two single-valued branches, give a name to the plot of each branch and then display the two together.

For a scientist, the easiest way to think of parametric plots is that the parameter, t, is time, and the plot represents the trajectory of a particle moving in the 2-dimensional (x,y)-plane in time.

By varying the frequencies of the two components, we obtain the Lissajoux figures:

Do[Do[
        ParametricPlot[{Sin[m t], Cos[n t]}, {t, -Pi, +Pi}], {n, 1, 
          3}], {m, 1, 3}]

which can be animated: Select the second cell-bracket that encompasses just the graphics outputs and double-click. Mathematica will collapse the graphics output cells into a single cell. Now double-click the graphics itself, or—while the 2nd encompassing bracket on the right is selcted—press Ctrl-Y or select the Cell > Animate Graphics menu command.

Exploring this feature, we check various frequency ratios:

Do[ParametricPlot[{Sin[t/(n 0.1)], 
          Cos[t]}, {t, -Pi, +Pi}], {n, 1, 9}]

When animated, this looks like a slinky being released to stretch down by gravity...

Do[ParametricPlot[{Sin[t Sqrt[n]], 
          Cos[n t]}, {t, -Pi, +Pi}], {n, 1, 9}]

Why are some of these curves closed, and other aren't? (E-mail me the answer.)

Now, back to the point about the ranges of the x variable, to plot the y variable as a single-valued function of it:

Do[ParametricPlot[{Cos[t] (2 Cos[t] + 1), 
          Sin[t] (2 Cos[n t] + 1)}, {t, 0, 2 Pi}], {n, 1, 
        3}]

I challenge anyone to come up with an algorithm that will determine how to divide such curves into single-valued branches, determine the ranges, and then plot them... (No, this is not homework; if you can solve it, publish it.)

Now consider a plot of Descartes' foil:

ParametricPlot[{3  t/(1 + t^3), 3  t^2/(1 + t^3)}, {t, -20, 
        20}]

The straight line is the asymptote, and should be at a 45 degree angle, which it is, except that the scale-ratio of the two axes if unequal. To remedy this, use the AspectRatio option:

ParametricPlot[{3  t/(1 + t^3), 3  t^2/(1 + t^3)}, {t, -20, 
        20}, AspectRatio -> 1]

Noting that all of these plots are graphics, use Mathematica's Help and enter “Graphics” to read up on all the options you can provide.

3D (Spatial) Curves

Let's now turn to 3-dimensional parametric graphs:

ParametricPlot3D[{Cos[t], Sin[t], 2 Sin[t/2]}, {t, 0, 
        4 Pi}]

To help with the (human) comprehension of how this curve curls in the space, you can color it, varying along its length:

ParametricPlot3D[{Cos[t], Sin[t], 2 Sin[t/2], Hue[Sin[t/8]]}, {t, 0, 
        4 Pi}]

ParametricPlot3D[{Cos[t], Sin[t], 2 Sin[t/3], Hue[Sin[t/12]]}, {t, 0, 
        6  Pi}]

ParametricPlot3D[{Cos[t], Sin[t], 2 Sin[t/3] Cos[t], 
        Hue[Sin[t/12]]}, {t, 0, 6  Pi}]

You can change the point of view, manually:

ParametricPlot3D[{Cos[t], Sin[t], 2 Sin[t/3] Cos[t], 
        Hue[Sin[t/12]]}, {t, 0, 6  Pi}, 
      ViewPoint -> {-3,  -1,  -2}]

or using the viewpoint-selector (Input > 3D ViewPoint Selector... menu) to insert the verbose command for the desired orientation:

ParametricPlot3D[{Cos[t], Sin[t], 2 Sin[t/3] Cos[t], 
        Hue[Sin[t/12]]}, {t, 0, 6  Pi}, 
      ViewPoint -> {-0.080,  -3.383,  -0.026}]

ParametricPlot3D[{Cos[t], Sin[t], 2 Sin[t/3] Cos[t], 
        Hue[Sin[t/12]]}, {t, 0, 6  Pi}, 
      ViewPoint -> {-0.080,  -3.383,  -0.026}, 
      Background -> GrayLevel[0.1]]

In all the above plots, we used the x- and y- plot coordinate to vary as Cos[t] and Sin[t]. Therefore, all the plots would look like circles from above:

ParametricPlot3D[{Cos[t], Sin[t], 2 Sin[t/3] Cos[t], 
        Hue[Sin[t/12]]}, {t, 0, 6  Pi}, ViewPoint -> {0,  0,  10}, 
      Background -> GrayLevel[0.1]]

3D (Spatial) Surfaces

Surfaces in 3-dimensional space are themselves 2-dimensional objects, so you need two parameters to plot them. We can continue using the x and y variables, which may coincide with the x and y plotting directions:

ParametricPlot3D[{x, y, x^2 - y^2}, {x, -2, 2}, {y, -2, 
        2}]

but need not:

ParametricPlot3D[{x^3, y/x, x^2 - y^2}, {x, -2, 2}, {y, -2, 
        2}]

ParametricPlot3D[{x, y, x^3 - 3  x y^2}, {x, -2, 2}, {y, -2, 
        2}, AspectRatio -> 1]

ParametricPlot3D[{x, y, x^3 - 3  x y^2}, {x, -2, 2}, {y, -2, 
        2}, AspectRatio -> 1, 
      ViewPoint -> {-0.080,  -3.383,  -0.026}]

ParametricPlot3D[{x, y, x^3 - 3  x y^2}, {x, -2, 2}, {y, -2, 
        2}, AspectRatio -> 1, ViewPoint -> {2,  1,  5}]

You can also plot defined functions

saddle = {x, y, x^3 - 3  x y^2}

ParametricPlot3D[saddle, {x, -2, 2}, {y, -2, 2}, 
      AspectRatio -> 1, ViewPoint -> {2,  1,  5}]

and functions with delayed evaluation (they are evaluated once the values of their arguments are given):

flap[x_, y_, a_] := {x, y, x^3 - a x y^2}

ParametricPlot3D[flap[x, y, 1], {x, -2, 2}, {y, -2, 2}, 
      AspectRatio -> 1, ViewPoint -> {2,  1,  5}]

And, of course, you can Do-loop a series of plots and animate them:

Do[ParametricPlot3D[flap[x, y, a], {x, -2, 2}, {y, -2, 2}, 
        AspectRatio -> 1, ViewPoint -> {2,  1,  5}], {a, 1, 
        3,  .2}]

Do[ParametricPlot3D[flap[x, y, a], {x, -2, 2}, {y, -2, 2}, 
        PlotRange -> {-20, 20}, ViewPoint -> {2,  1,  5}], {a, 1, 
        3,  .2}]

Here's a folded-over-and-accross-itself surface:

ParametricPlot3D[{Cos[x], Sin[y], Sin[x] Sin[y]}, {x, -2, 
        2}, {y, -2, 2}, AspectRatio -> 1, 
      ViewPoint -> {2,  1,  5}]

By varying the ViewPoint parameters:

ParametricPlot3D[{Cos[x], Sin[y], Sin[x] Sin[y]}, {x, -2, 
        2}, {y, -2, 2}, AspectRatio -> 1, 
      ViewPoint -> {3,  -2,  0}]

ParametricPlot3D[{Cos[x], Sin[y], Sin[x] Sin[y]}, {x, -2, 
        2}, {y, -2, 2}, AspectRatio -> 1, 
      ViewPoint -> {3,  -9,  0}]

ParametricPlot3D[{Cos[x], Sin[y], Sin[x] Sin[y]}, {x, -2, 
        2}, {y, -2, 2}, AspectRatio -> 1, 
      ViewPoint -> {-1,  -3,  0}]

ParametricPlot3D[{Cos[x], Sin[y], Sin[x] Sin[y]}, {x, -2, 
        2}, {y, -2, 2}, AspectRatio -> 1, 
      ViewPoint -> {-3,  -3,  0}]

you can make the animated graphics rotate:

Do[ParametricPlot3D[{Cos[x], Sin[y], Sin[x] Sin[y]}, {x, -2, 
          2}, {y, -2, 2}, AspectRatio -> 1, 
        ViewPoint -> {Sin[n Pi 0.1], Cos[n Pi 0.1],  0}], {n, 0, 
        9}]