Three-Dimensional Mathematica Graphics (Section 2.3)

Extract from Mathematica Graphics: An Intensive Tutorial

by Tom Wickham-Jones

This HTML document is based on Mathematica Graphics: An Intensive Tutorial by Tom Wickham-Jones. It was adapted by Martin Kraus for non-commercial use.

Mathematica and MathLink are registered trademarks, and MathReader, MathSource and 3-Script are trademarks of Wolfram Research, Inc.

All other product names mentioned are trademarks of their producers.

Copyright 1992 by Wolfram Research, Inc.

All rights reserved. No part of this document may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, without the prior written permission of the copyright holder.

2.3 Graphics Packages

Mathematica contains a powerful programming language. Programs can be written in top-level Mathematica code which operate on graphics primitives and produce some particular type of graphic. There are many types of three-dimensional plots which are desirable, such as contour plots, bar charts or vector fields. Mathematica comes with code to produce these. This code is stored in what we call a Mathematica package.

The Mathematica packages are well described in the Mathematica 3.0 on-line help and in the book Mathematica 3.0 Standard Add-on Packages by Wolfram Research, Inc. These describe each of the packages and give examples of its functions. In this section I shall give a brief look at a few of them. One important thing to remember about these packages is that for the functions to be available to Mathematica the package must be loaded.

 This loads the package which defines polyhedra. In:= <

By using this notation, with a back quote `, Mathematica ensures that the same command will load the package on every computer system on which Mathematica runs, even when the file naming conventions for those systems are different.

 These are the packages which have been loaded. In:= \$Packages Out= {"Utilities`FilterOptions`", "Geometry`Polytopes`", "Graphics`Polyhedra`", "Global`", "System`"}

2.3.1 More Data Plots

In the previous section the command ListPlot3D was suggested as a method to plot data. However, you may wish to plot data points which are not regularly spaced over a grid. This is done by the function ListSurfacePlot3D which corresponds to ParametricPlot3D with two parameters. ListSurfacePlot3D is defined in the package Graphics`Graphics3D`.

 This will load the package. In:= <

Plotting a list instead of an array of points is done with the function ScatterPlot3D which corresponds to ParametricPlot3D with one parameter. ScatterPlot3D is also defined in the package Graphics`Graphics3D`, thus we do not need to load the package again.

 This generates a list of data points. In:= data = Table[{Cos[t], Sin[t], Cos[2 t]}, {t, 0, 2 Pi, 0.2}]; This produces a scatter plot. In:= ScatterPlot3D[data] Out= - Graphics3D - ScatterPlot3D has some additional options like PlotJoined and PlotStyle. In:= ScatterPlot3D[data, PlotJoined -> True, PlotStyle -> Thickness[0.04]] Out= - Graphics3D -

The package Graphics`Graphics3D` also defines an alternative to ListPlot3D, namely BarChart3D.

 This is an array of random numbers. In:= data = Table[Random[], {i, 4}, {j,4}]; This plots a bar chart in three dimensions. In:= BarChart3D[data] Out= - Graphics3D -

Sometimes a combination of a three-dimensional plot and a density plot is useful. This can be done with ListShadowPlot3D for data and ShadowPlot3D for function plotting. Both commands are defined in the package Graphics`Graphics3D`.

 This produces a three-dimensional surface and its flat shadow. The option PlotPoints controls the number of sampling points. In:= ShadowPlot3D[-Cos[x^2] + Sin[y^2], {x, -2, 2}, {y, -2, 2}, PlotPoints -> 8] Out= - Graphics3D -

In the package Graphics`Graphics3D` facilities are given to change the position of the shadow and the mesh style which is used. The Mathematica 3.0 on-line help and the Wolfram Research book Mathematica 3.0 Standard Add-on Packages describe this and all other Mathematica packages in detail.

2.3.2 ContourPlot3D

So far we have plotted lines and surfaces which were either parametrized by one or two variables or given by some data points. On the other hand ContourPlot3D plots the surface showing a particular value (by default 0) of a function of x, y and z. CountourPlot3D and the corresponding data plotting command ListCountourPlot3D are defined in the package Graphics`CountourPlot3D`.

 First the package is loaded. In:= < {4,3}, Boxed -> False] Out= - Graphics3D -

2.3.3 PlotVectorField3D

PlotVectorField3D (together with PlotGradientField3D and ListPlotVectorField3D) is defined in the package Graphics`PlotField3D`.

 This loads the package. In:= < True. In:= PlotVectorField3D[(z^2 + 1) {-y, x, z / 10}, {x, -1, 1}, {y, -1, 1}, {z, 0, 2}] Out= - Graphics3D -