Three-Dimensional Mathematica Graphics (Section 2.2)

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 prodcut 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.2 Altering Pictures

Now we have seen how to make a picture. Often we wish to redisplay it or to change it in some way. This is done with the command Show.

Show[image] redisplay image
Show[image, option -> setting] redisplay image with option
Show[image1, image2] combine image1 and image2 and display the result
Using the command Show.

Redisplaying the image is simple. To alter the image we must examine the options which are available for graphics.

2.2.1 Command Options

In Mathematica many built-in commands have options which alter their behavior. The options are given as rules and are given with "->". This description of passing options to a function is valid for any command in Mathematica, not just the graphics commands.

Here the background color of the plot is set to be a GrayLevel of 0, which is black. We save the plot as the symbol a to use it later. In[18]:= a = ParametricPlot3D[{t, Sin[t], Cos[t]}, {t, 0, 2 Pi}, Background -> GrayLevel[0]]

Out[18]= - Graphics3D -
 
The options of ParametricPlot3D with their default values are shown. In[19]:= Options[ParametricPlot3D]

Out[19]= {AmbientLight -> GrayLevel[0.], AspectRatio -> Automatic, Axes -> True, AxesEdge -> Automatic, AxesLabel -> None, AxesStyle -> Automatic, Background -> Automatic, Boxed -> True, BoxRatios -> Automatic, BoxStyle -> Automatic, ColorOutput -> Automatic, Compiled -> True, DefaultColor -> Automatic, Epilog -> {}, FaceGrids -> None, ImageSize -> Automatic, Lighting -> True, LightSources -> {{{1., 0., 1.}, RGBColor[1, 0, 0]}, {{1., 1., 1.}, RGBColor[0, 1, 0]}, {{0., 1., 1.}, RGBColor[0, 0, 1]}}, Plot3Matrix -> Automatic, PlotLabel -> None, PlotPoints -> Automatic, PlotRange -> Automatic, PlotRegion -> Automatic, PolygonIntersections -> True, Prolog -> {}, RenderAll -> True, Shading -> True, SphericalRegion -> False, Ticks -> Automatic, ViewCenter -> Automatic, ViewPoint -> {1.3, -2.4, 2.}, ViewVertical -> {0., 0., 1.}, DefaultFont :> $DefaultFont, DisplayFunction :> $DisplayFunction, FormatType :> $FormatType, TextStyle :> $TextStyle}
 
This uses Show to change the option for background color to be white. The drawing color, which is set by the option DefaultColor, changes according to the background. In[20]:= Show[a, Background -> GrayLevel[1]]
Out[20]= - Graphics3D -
 
This shows the default setting of the option PlotRange. In[21]:= Options[Plot, PlotRange]

Out[21]= {PlotRange -> Automatic}
 
To change a default setting one uses the command SetOptions. In[22]:= SetOptions[ParametricPlot3D, PlotRange -> All]

Out[22]= {AmbientLight -> GrayLevel[0.], AspectRatio -> Automatic, Axes -> True, AxesEdge -> Automatic, AxesLabel -> None, AxesStyle -> Automatic, Background -> Automatic, Boxed -> True, BoxRatios -> Automatic, BoxStyle -> Automatic, ColorOutput -> Automatic, Compiled -> True, DefaultColor -> Automatic, Epilog -> {}, FaceGrids -> None, ImageSize -> Automatic, Lighting -> True, LightSources -> {{{1., 0., 1.}, RGBColor[1, 0, 0]}, {{1., 1., 1.}, RGBColor[0, 1, 0]}, {{0., 1., 1.}, RGBColor[0, 0, 1]}}, Plot3Matrix -> Automatic, PlotLabel -> None, PlotPoints -> Automatic, PlotRange -> All, PlotRegion -> Automatic, PolygonIntersections -> True, Prolog -> {}, RenderAll -> True, Shading -> True, SphericalRegion -> False, Ticks -> Automatic, ViewCenter -> Automatic, ViewPoint -> {1.3, -2.4, 2.}, ViewVertical -> {0., 0., 1.}, DefaultFont :> $DefaultFont, DisplayFunction :> $DisplayFunction, FormatType :> $FormatType, TextStyle :> $TextStyle}
 
Let's change it back. The ";" at the end suppresses the result from printing out. In[23]:= SetOptions[ParametricPlot3D, PlotRange -> Automatic];

Settings for Options

The permissible values for a given option vary according to the actual effect of the option. Some options take numbers to control the number of points at which a function is evaluated, some options control the appearance of axes and these take style directives and some options take a simple Boolean True or False to decide whether to do something or not.

Automatic use an optimal internal algorithm
All include everything
None do not include this
True do this
False do not do this
Some common settings for options.
The value is Automatic. This means use an internal algorithm to choose some good value. In[24]:= Options[ParametricPlot3D, Background]

Out[24]= {Background -> Automatic}
 
The value is True. This means do draw a box. In[25]:= Options[Plot3D, Boxed]

Out[25]= {Boxed -> True}
 

FullOptions

Often it is useful to use an internal algorithm to set an option, for example setting PlotRange, BoxRatios or AspectRatio to be Automatic. Sometimes you want to know the value which was actually used. This functionality is provided by FullOptions.

FullOptions shows the literal value which was used in the last plot called a. In[26]:= FullOptions[a, BoxRatios]

Out[26]= {3.14159, 0.999099, 1.}
 

2.2.2 Three-Dimensional Graphics

Having seen how to issue commands I shall review some ways to change three-dimensional graphics using options. This is not a detailed list of all the options for the graphics.

Axes axes for a plot
AxesLabel labels for the axes
Boxed a box around the plot
PlotRange range of coordinates
ViewPoint how the object is viewed
Some useful three-dimensional options.

Axes, AxesLabel and Boxed

This gives a z axis but no x or y axes. In[27]:= ParametricPlot3D[{Sqrt[t] Cos[t], Sqrt[t] Sin[t], Sqrt[t]}, {t, 0, 6 Pi}, Axes -> {False, False, True}]
Out[27]= - Graphics3D -
 
The axes can be labeled. In[28]:= ParametricPlot3D[{Sqrt[t] Cos[t], Sqrt[t] Sin[t], Sqrt[t]}, {t, 0, 6 Pi}, AxesLabel ->{"x", "y", "z"}]
Out[28]= - Graphics3D -
 
This still draws the box around the image. In[29]:= Show[%, Axes -> False]
Out[29]= - Graphics3D -
 
This just draws the image. In[30]:= Show[%, Boxed -> False]
Out[30]= - Graphics3D -
 

PlotRange

The PlotRange determines the region of user coordinates which are actually shown. In[31]:= Options[Plot3D, PlotRange]

Out[31]= {PlotRange -> Automatic}
 
The default value of PlotRange is used to omit points which are scattered away from the group of the majority of the points. In[32]:= Plot3D[Exp[-Sqrt[x^2 + y^2]], {x, -2, 2}, {y, -2, 2}, Axes -> False, Boxed -> False]
Out[32]= - SurfaceGraphics -
 
To see all the points specified in the primitives use PlotRange -> All. In[33]:= Show[%, PlotRange -> All]
Out[33]= - SurfaceGraphics -
 
FullOptions shows the value of PlotRange which was used. One can also give explicit values to the PlotRange option, for example PlotRange -> {0, 1}. In[34]:= FullOptions[%, PlotRange]

Out[34]= {{-2., 2.}, {-2., 2.}, {0.0355834, 1.02352}}
 

ViewPoint

This shows a more end-on view of this surface. The %% refers to the next to last output. In[36]:= Show[%%, ViewPoint -> {1.3, -2.4, .3}]
Out[36]= - SurfaceGraphics -
 

Often when viewing a three-dimensional surface it is necessary to experiment with a number of ways to view it to find the one which is most pleasing. Many of the Mathematica front ends have specialized tools to allow this to be done. (In this HTML document the view point of any image can be changed by dragging it.)


next page: 2.3 Graphics Packages back to table of contents