Are you sure?
This action might not be possible to undo. Are you sure you want to continue?
Visualization and Graphics
For use with Wolfram Mathematica® 7.0 and later. For the latest updates and corrections to this manual: visit reference.wolfram.com For information on additional copies of this documentation: visit the Customer Service website at www.wolfram.com/services/customerservice or email Customer Service at info@wolfram.com Comments on this manual are welcomed at: comments@wolfram.com Printed in the United States of America. 15 14 13 12 11 10 9 8 7 6 5 4 3 2
©2008 Wolfram Research, Inc. All rights reserved. No part of this document may be reproduced or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, without the prior written permission of the copyright holder. Wolfram Research is the holder of the copyright to the Wolfram Mathematica software system ("Software") described in this document, including without limitation such aspects of the system as its code, structure, sequence, organization, “look and feel,” programming language, and compilation of command names. Use of the Software unless pursuant to the terms of a license granted by Wolfram Research or as otherwise authorized by law is an infringement of the copyright. Wolfram Research, Inc. and Wolfram Media, Inc. ("Wolfram") make no representations, express, statutory, or implied, with respect to the Software (or any aspect thereof), including, without limitation, any implied warranties of merchantability, interoperability, or fitness for a particular purpose, all of which are expressly disclaimed. Wolfram does not warrant that the functions of the Software will meet your requirements or that the operation of the Software will be uninterrupted or error free. As such, Wolfram does not recommend the use of the software described in this document for applications in which errors or omissions could threaten life, injury or significant loss. Mathematica, MathLink, and MathSource are registered trademarks of Wolfram Research, Inc. J/Link, MathLM, .NET/Link, and webMathematica are trademarks of Wolfram Research, Inc. Windows is a registered trademark of Microsoft Corporation in the United States and other countries. Macintosh is a registered trademark of Apple Computer, Inc. All other trademarks used herein are the property of their respective owners. Mathematica is not associated with Mathematica Policy Research, Inc.
Contents
Graphics and Sound
Basic Plotting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Options for Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Redrawing and Combining Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Manipulating Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ThreeDimensional Surface Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Plotting Lists of Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Parametric Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Some Special Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Sound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2 9 14 16 22 25 29 31
The Structure of Graphics and Sound
The Structure of Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . TwoDimensional Graphics Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Graphics Directives and Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Coordinate Systems for TwoDimensional Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Labeling TwoDimensional Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Insetting Objects in Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Density and Contour Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ThreeDimensional Graphics Primitives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ThreeDimensional Graphics Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Coordinate Systems for ThreeDimensional Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . Lighting and Surface Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Labeling ThreeDimensional Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 39 45 51 60 64 67 71 76 81 89 96
Efficient Representation of Many Primitives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 Formats for Text in Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 Graphics Primitives for Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 The Representation of Sound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 Exporting Graphics and Sounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 Importing Graphics and Sounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
. . . . . . . Cropping. . . . . . . . . . . . 164 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . and Adding Margins to Graphics . . . . . . . . . . . . . . . . . . . . .Editing Mathematica Graphics Introduction . . . . . . . 160 Graphics as Input . . . . . . . . . . . . . . . . . . . . . . . . . 138 Resizing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 Interacting with 3D Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 Drawing Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 Selecting Graphics Objects . . . . . . . . 128 Reshaping Graphics Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
….xk <D Plot@8 f1 .xmin . 8x.x1 . This plots a graph of sinHxL as a function of x from 0 to 2 p. 2 Pi<D 1. 8x.xmax <D Plot@ f .xmax <D plot several functions together Basic plotting functions. In[3]:= Plot@Tan@xD. 3<D 6 4 2 Out[3]= 3 2 1 2 4 6 1 2 3 . .8x. 8x.8x. In[1]:= plot f as a function of x from xmin to xmax plot f over a series of segments. 0.Pi ê 2.xmin .0 0. .Graphics and Sound Basic Plotting Plot@ f .3. In[2]:= Plot@Tan@xD.3.8x. Mathematica will try to choose appropriate scales. . f2 .x0 .5 Out[1]= 0.…<.0 1 2 3 4 5 6 You can plot functions that have singularities. potentially breaking the curve at each of the xi Plot@Sin@xD. Pi ê 2.5 1. 3<D 6 4 2 Out[2]= 3 2 1 2 4 6 1 2 3 The singularities can be omitted from the plot by specifying them in the plot's range.
if you want to get the very best possible pictures for your particular purposes. Sin@3 xD<. There is a general mechanism for specifying “options” in Mathematica functions. In[6]:= Plot@y@xD ê. In[5]:= NDSolve@8y '@xD == Sin@y@xDD. It has to work out what the scales should be. you can include a sequence of rules of the form name > value. 8x. y. Any option for which you do not give an explicit rule is taken to have its “default” value. . 2 Pi<D 1. where the function should be sampled. you may have to help Mathematica in making some of its choices. to specify the values for various options. 0.0 2. 0. 4<D Out[5]= 88y Ø InterpolatingFunction@880.0 1 2 3 4 5 6 This finds the numerical solution to a differential equation. Each option has a definite name.5 1.0 0. Mathematica will probably make pretty good choices.5 1 2 3 4 Options for Graphics When Mathematica plots a graph for you. Sin@2 xD.. Most of the time. 8x. <>D<< Here is a plot of the solution. 8x. As the last arguments to a function like Plot.<<.2 Visualization and Graphics You can give a list of functions to plot. In[4]:= Plot@8Sin@xD. how the axes should be drawn. 4<D 3.0 1. However.5 Out[4]= 0. as discussed in "Numerical Differential Equations". A different color will automatically be used for each function. 4. %. and so on. y@0D == 1<. 0. it has to make many choices.5 Out[6]= 2.
option name default value AspectRatio 1ëGoldenRatio Axes AxesLabel True None AxesOrigin BaseStyle FormatType Frame FrameLabel Automatic 8< TraditionalFoÖ rm False None the heighttowidth ratio for the plot. give a list in clockwise order starting with the lower x axis what tick marks to draw if there is a frame. "Redrawing and Combining Plots" will also discuss how you can change some of the options. ylabel< for both axes the point at which axes cross the default style to use for the plot the default format type to use for text in the plot whether to draw a frame around the plot labels to be put around the frame.xmax <.option>valueD make a plot. None gives no tick marks what grid lines to include. Usually you will need to use at most a few of them at a time. trying a sequence of different settings for various options. Each time you produce a plot. ylabel specifies a label for the y axis. If you want to optimize a particular plot.xmin . Automatic sets it from the absolute x and y coordinates whether to include axes labels to be put on the axes. you can specify options for it.8x. These can also be used in Show . specifying a particular value for an option Choosing an option for a plot. you will probably do best to experiment. .Visualization and Graphics 3 Plot@ f . 8xlabel. All includes all points what tick marks to draw if there are axes. Automatic includes a grid line for every major tick mark an expression to be printed as a label for the plot the range of coordinates to include in the plot. None gives no tick marks FrameTicks GridLines Automatic None PlotLabel PlotRange Ticks None Automatic Automatic Some of the options for Plot . A function like Plot has many options that you can set. even after you have produced the plot.
5 0. 8x.0 2.0 0.5 3.0 1.0 .0 This draws axes on a frame around the plot.0 0.0 0. In[2]:= Plot@Sin@x ^ 2D.5 2.0 0.5 1.0 0.0 1.5 Out[3]= 0.0 0. You can give any piece of text by putting it inside a pair of double quotes.0 0. 0. AxesLabel > 8"x value".5 1. In[3]:= Plot@Sin@x ^ 2D.5 Out[1]= 0. In[1]:= Plot@Sin@x ^ 2D.5 Out[2]= 0.5 1.0 This specifies labels for the x and y axes.5 1. 8x.0 2.0 2. Frame > True. The expressions you give as labels are printed just as they would be if they appeared as TraditionalForm Mathematica output. 0. 3<.5 2.0 0. 3<.4 Visualization and Graphics Here is a plot with all options having their default values.0 1.0 0.0 0.5 3.0 0. 3<D 1. in any order.0 1. 3<. GridLines > AutomaticD 1. In[4]:= Plot@Sin@x ^ 2D. 8x.5 1.5 3. 0.0 x value You can give several options at the same time.0 1. Sin@x ^ 2D<D sinIx2 M 1. 8x.5 Out[4]= 0.5 3.5 1. Frame > TrueD 1.5 2.5 1. 0.5 2.0 2.
5 2. In[5]:= Plot@Sin@x ^ 2D. 8x. show at least a large fraction of the points. you can control exactly what ranges of x and y coordinates are included in your plot. use internal algorithms do not include this include everything do this do not do this When Mathematica makes a plot.5 1.0 Automatic None All True False Some common settings for various options.0 1. 3<.5 1. the parts where it gets too large will be cut off. 0.Visualization and Graphics 5 Setting the AspectRatio option changes the whole shape of your plot. it tries to set the x and y scales to include only the “interesting” parts of the plot.yrange< Settings for the option PlotRange. or has singularities. including the “interesting” region (the default setting) show all points show a specific range of y values show the specified ranges of x and y values Automatic All 8ymin . If your function increases very rapidly.0 0.5 Out[5]= 0. By specifying the option PlotRange.0 0. AspectRatio gives the ratio of width to height. AspectRatio > 1D 1.ymax < 8xrange.0 2. Its default value is the inverse of the Golden Ratio~supposedly the most pleasing shape for a rectangle. .5 3.
but it can never sample the infinite number that you would need to reproduce the function exactly. 1<D 1.5 1.8 Out[6]= 0.0 0.2 0. to how finely Mathematica will ever sample a function. the longer it will take Mathematica to plot any function.6 0.5 1. which you can set.0 0.5 0.5 Out[7]= 1. option name default value PlotStyle Automatic ClippingStyle None a list of lists of graphics primitives to use for each curve (see "Graphics Directives and Options") what to draw when curves are clipped . it can always miss features of the function.5 2. 8x. By increasing PlotPoints.0 0. Mathematica tries to sample more points in the region where the function wiggles a lot.2<D 1. in places where your function wiggles a lot.0 2.4 0. however.2 1. In general. In[6]:= Plot@Sin@x ^ 2D. With the y limits specified here. even a smooth one. There is.0 0. PlotRange > 80. Mathematica tries to adapt its sampling of your function to the form of the function.1. . 0.5 1. 3<. the larger you set PlotPoints to be.0 It is important to realize that since Mathematica can only sample your function at a limited number of points. As a result.6 Visualization and Graphics The setting for the option PlotRange gives explicit y limits for the graph. In[7]:= 1 x Plot@Sin@1 ê xD. but it is still possible to miss something. Mathematica adaptively samples the functions. 8x. the bottom of the curve is cut off. 1. Mathematica will use more points. Of course.0 Mathematica always tries to plot functions as smooth curves. there are slight glitches in the plot. The function sin J N wiggles infinitely often when x > 0. As a result. a limit.0 1. you can make Mathematica sample your function at a larger number of points.5 3. increasing the number of samples near interesting features.
8x.5 2. In[10]:= Plot@8Sin@x ^ 2D.5 3. This uses PlotStyle to specify a dashed curve. 3<. 8x.0 2.0 0. PlotStyle Ø 8Red. 3<.0 0.0 When plotting multiple functions.0 .5 1. 0.5 2.0 1.5 2. Thick<<D 1.5 Out[10]= 0.0 2.0 0.0 1.5 3.0 When a PlotStyle contains a sublist.5 1. These cannot be used in Show . 0.5 Out[8]= 0.0 0. Cos@x ^ 2D<.5 1. Cos@x ^ 2D<.5 1.Visualization and Graphics 7 Filling FillingStyle PlotPoints MaxRecursion None Automatic 50 Automatic filling to insert under each curve style to use for filling the initial number of points at which to sample the function the maximum number of recursive subdivi sions allowed More options for Plot .5 1.5 3. the settings are combined.0 0. 8x. PlotStyle Ø 8Red. 3<. Blue<D 1. PlotStyle Ø DashedD 1. 0.5 1. In[9]:= Plot@8Sin@x ^ 2D.0 1.0 0.0 2. PlotStyle settings in a list are used sequentially for each function.5 Out[9]= 0. 8Blue. In[8]:= Plot@Sin@x ^ 2D.
5 1.9. Cos@x ^ 2D<. PlotRange Ø 0. In[11]:= Plot@8Sin@x ^ 2D.0 1.0 Setting ClippingStyle to a list defines the style for the parts cut off at the bottom and top. PlotRange Ø 0. Cos@x ^ 2D<.0 This specifies filling between the curve and the x axis. Cos@x ^ 2D<. Red<D 0. 3<. 8x.0 2. 8x. 0.5 Out[11]= 0. In[12]:= Plot@8Sin@x ^ 2D.8 Visualization and Graphics By default nothing is indicated when the PlotRange is set.0 Setting ClippingStyle to Automatic draws a dashed line where a curve is cut off.0 1. ClippingStyle Ø AutomaticD 0.9.5 2.9D 0.5 1. In[14]:= Plot@Sin@x ^ 2D. In[13]:= Plot@8Sin@x ^ 2D. ClippingStyle Ø 8Green. PlotRange Ø 0. 3<.0 2.5 0. 8x.5 0. 0.5 3. 0. 3<.5 3.5 1. 0.5 3. Filling Ø AxisD Out[14]= .0 2. 3<.5 2.0 1.5 Out[13]= 0.5 0.5 2.5 Out[12]= 0. 8x. so that it cuts off curves.
3<.option>valueD Show@plot1 .5 1. When you redraw plots.5 3. Filling Ø BottomD Out[15]= This specifies a specific filling to be used only for the first curve. Filling Ø 81 Ø 82<<. 0. show the underlying textual description of the plot . 8x.0 2.plot2 . so that you can later redraw it. 0. Filling colors are automatically blended where they overlap. 8x.5<D Out[16]= This shows a filling from the first curve to the second using a nondefault filling style.5 2. FillingStyle Ø LightBrownD 1. you can change some of the options you use.5 Out[17]= 0. Cos@xD<.…<D draw an array of plots InputForm@plotD Functions for manipulating plots. In[15]:= Plot@8Sin@xD. Filling Ø 81 Ø .plot2 . redraw a plot with options changed combine several plots Show@plot. 3<.0 0. Cos@xD<. Cos@xD<. 3<.5 1.Visualization and Graphics 9 The filling can be specified to extend to an arbitrary height. 8x. In[16]:= Plot@8Sin@xD.0 1.…D GraphicsGrid@88plot1 . In[17]:= Plot@8Sin@xD.0 Redrawing and Combining Plots Mathematica saves information about every plot you produce.…<. such as the bottom of the graphic.0 0. 0.
PlotLabel > "A Chebyshev Polynomial"D A Chebyshev Polynomial 2.1.5 0.5 1.0 0. 8x. .0 1. All of the options for the resulting graphic will be based upon the options of the first graphic in the Show expression. You can also use Show to combine plots.5 0.5 1. and changes another option in it.5 Out[1]= 1. This changes the choice of y scale. if you are trying to find the best possible setting of options.5 0. In[1]:= Plot@ChebyshevT@7. 1<D 1. In[2]:= Show@%.5 1.5 1. PlotRange > 8.10 Visualization and Graphics Here is a simple plot.0 0.5 1.5 1. In[3]:= Show@%.0 When you redraw the plot.0 1.1.0 This takes the plot from the previous line.0 0.0 1.5 0.5 0. you can look at the same plot in many different ways. .0 1.0 By using Show with a sequence of different options.0 0.0 0.0 Out[2]= 1.5 Out[3]= 1.5 0.0 0. you can change some of the options. 2<D 2. You may want to do this. for example. xD.
2 0. 10<D 0. In[5]:= gy1 = Plot@BesselY@1. 80.5 Out[7]= 2 0. 1. Doing these kinds of manipulations does not require the use of Show.0 0.4 2 4 6 8 10 Here is a plot of Y1 HxL from x = 1 to 10. In[6]:= Options@gj0.6 Out[4]= 0. 1.0 0.4 0. In[4]:= gj0 = Plot@BesselJ@0.8 6 8 10 Out[5]= Plot specifies an explicit PlotRange for each graphic.Visualization and Graphics 11 This sets gj0 to be a plot of J0 HxL from x = 0 to 10.4 0.2 0.5 4 6 8 10 All Mathematica graphics are expressions and can be manipulated in the same way as any other expression. 0. PlotRangeD Out[6]= 8PlotRange Ø 880. 8x. 8x. 10<.402759.<<< This uses PlotRange to override the explicit value set for gj0. PlotRange Ø AutomaticD 1. xD. In[7]:= gjy = Show@gj0.8 0.2 4 0. . gy1.4 0. 10<D 1.2 0.6 0. xD.
12
Visualization and Graphics
This replaces all instances of the symbol Line with the symbol Point in the graphics expression represented by gj0.
In[8]:=
gj0 ê. Line Ø Point
1.0 0.8 0.6
Out[8]=
0.4 0.2 2 4 6 8 10
0.2 0.4
Using Show@plot1 , plot2 , …D you can combine several plots into one. GraphicsGrid allows you to draw several plots in an array.
GraphicsGrid@88plot11 ,plot12 ,…<,…<D
draw a rectangular array of plots
GraphicsRow @8plot1 ,plot2 ,…<D
draw several plots side by side
GraphicsColumn@8plot1 ,plot2 ,…<D
draw a column of plots
GraphicsGridAplots,Spacings>8h,v<E
put the specified horizontal and vertical spacing between the plots
Drawing arrays of plots. This shows the previous plots in an array.
In[9]:=
GraphicsGrid@88gj0, gjy<, 8gy1, gjy<<D
1.0 0.8 0.6 0.4 0.2 0.2 0.4 0.4 0.2 0.2 0.4 0.6 0.8 0.5 4 6 8 10 2 4 6 8 10 1.0 0.5 2 0.5 4 6 8 10
Out[9]=
1.0 0.5 2 4 6 8 10
Visualization and Graphics
13
If you redisplay an array of plots using Show , any options you specify will be used for the whole array, rather than for individual plots.
In[10]:=
Show@%, Frame > True, FrameTicks > NoneD
1.0 0.8 0.6 0.4 0.2 0.2 0.4 0.4 0.2 0.2 0.4 0.6 0.8 0.5 4 6 8 10 2 4 6 8 10 1.0 0.5 2 0.5 4 6 8 10
Out[10]=
1.0 0.5 2 4 6 8 10
GraphicsGrid by default puts a narrow border around each of the plots in the array it gives. You can change the size of this border by setting the option Spacings > 8h, v<. The parameters h and v give the horizontal and vertical spacings to be used. The Spacings option uses the width and height of characters in the default font to scale the h and v parameters by default, but it is generally more useful in graphics to use Scaled coordinates. Scaled scales widths and heights so that a value of 1 represents the width and height of one element of the grid.
This increases the horizontal spacing, but decreases the vertical spacing between the plots in the array.
In[11]:=
GraphicsGrid@88gj0, gjy<, 8gy1, gjy<<, Spacings > 8Scaled@.3D, Scaled@0D<D
1.0 0.8 0.6 0.4 0.2 0.2 0.4 0.4 0.2 0.2 0.4 0.6 0.8 2 4 6 8 10 1.0 0.5 2 0.5 1.0 4 6 8 10 0.5 2 0.5 4 6 8 10 4 6 8 10
Out[11]=
When you make a plot, Mathematica saves the list of points it used, together with some other information. Using what is saved, you can redraw plots in many different ways with Show. However, you should realize that no matter what options you specify, Show still has the same basic set of points to work with. So, for example, if you set the options so that Mathematica displays a small portion of your original plot magnified, you will probably be able to see the individual sample points that Plot used. Options like PlotPoints can only be set in the original Plot command itself. (Mathematica always plots the actual points it has; it avoids using smoothed or splined curves, which can give misleading results in mathematical graphics.)
Here is a simple plot.
14
Visualization and Graphics
Here is a simple plot.
In[12]:=
Plot@Cos@xD, 8x,  Pi, Pi<D
1.0 0.5
Out[12]=
3
2
1 0.5 1.0
1
2
3
This shows a small region of the plot in a magnified form. At this resolution, you can see the individual line segments that were produced by the original Plot command.
In[13]:=
Show@%, PlotRange > 880, .005<, 8.99999, 1<<D
1.000000 0.999998
Out[13]=
0.999996 0.999994 0.999992 0.999990
Manipulating Options
There are a number of functions built into Mathematica which, like Plot, have various options you can set. Mathematica provides some general mechanisms for handling such options. If you do not give a specific setting for an option to a function like Plot, then Mathematica will automatically use a default value for the option. The function Options@ function, optionD allows you to find out the default value for a particular option. You can reset the default using SetOptions@ function, option > valueD. Note that if you do this, the default value you have given will stay until you explicitly change it.
give a list of the current default settings for all options give the default setting for a particular option reset defaults
Manipulating default settings for options.
Options@ functionD Options@ function,optionD SetOptions@ function,option>value,…D
PlotRangeD 7 7 Out[6]= 9PlotRange Ø 994. 94. You can get this information by applying the Options function to these graphics objects.0 0. In[1]:= Options@Plot. PlotRange > AllD. In[2]:= SetOptions@Plot. Until you explicitly reset it.Visualization and Graphics 15 Here is the default setting for the PlotRange option of Plot . In[3]:= Options@Plot. 20<D 1. with default settings for all options. 1.optionD AbsoluteOptions@plot. In[5]:= Options@g. In[6]:= AbsoluteOptions@g.optionD Getting information on options used in plots. 20. 0. the default for the PlotRange option will now be All.5 5 10 15 20 The setting used for the PlotRange option was All. PlotRangeD Out[5]= 8PlotRange Ø 8All. show all the options used for a particular plot show the setting for a specific option show the absolute form used for a specific option. Here is a plot.5 Out[4]= 1. In[4]:= g = Plot@SinIntegral@xD.=. even if the setting for the option is Automatic or All Options@plotD Options@plot. All<< AbsoluteOptions gives the absolute automatically chosen values used for PlotRange. PlotRangeD Out[1]= 8PlotRange Ø 8Full. PlotRangeD Out[3]= 8PlotRange Ø All< The graphics objects that you get from Plot or Show store information on the options they use. Automatic<< This resets the default for the PlotRange option. The semicolon stops Mathematica from printing out the rather long list of options for Plot .08163 µ 10 .08163 µ 10 .85194=== . 8x.
at which point the output cell will be converted into a new input cell.5 In[7]:= AbsoluteOptionsB 1.8y. 3<. This makes a threedimensional plot of the function sinHxyL.16 Visualization and Graphics While it is often convenient to use a variable to represent a graphic as in the above examples.ymin .8x. the graphic itself can be evaluated directly. PlotRangeF 7 7 Out[7]= 9PlotRange Ø 994.xmax <.xmin . 0. When a plot created with no explicit ImageSize is placed into an input cell. 8y.=.0 0. In[1]:= Plot3D@Sin@x yD. it will automatically shrink to more easily accommodate input. The following input cell was created by copying and pasting the graphical output created in the previous example. 8x. 20.5 5 10 15 20 .08163 µ 10 . 1. 3<D Out[1]= . The typical ways to do this in the notebook interface are to copy and paste the graphic or to simply begin typing in the graphical output cell. 94. 1.08163 µ 10 .85194=== ThreeDimensional Surface Plots Plot3D@ f .ymax <D make a threedimensional plot of f as a function of the variables x and y Basic 3D plotting function. 0.
Visualization and Graphics 17 Threedimensional graphics can be rotated in place by dragging the mouse inside of the graphic.3. ylabel. Some are discussed here. zlabel< for all axes the default style to use for the plot whether to draw a threedimensional box around the surface how to draw grids on faces of the bounding box.Full. Use the Ctrl key (Cmd key on Macintosh) to zoom. Dragging inside of the graphic causes the graphic to tumble in a direction that follows the mouse.1<ê2 81. The first set of options for threedimensional plots is largely analogous to those provided in the twodimensional case. All draws a grid on every face style specification for labels simulated light sources to use whether an xy mesh should be drawn on the surface the range of z or other values to include whether to make the circumscribing sphere fit in the final display area angle of the field of view point to display at the center the point in space from which to look at the surface position and direction of a simulated camera direction to make vertical how to draw boundary lines for surfaces how to draw clipped parts of surfaces how to determine the color of the surfaces filling under each surface . others are described in "The Structure of Graphics and Sound".0.2. Automatic= False All 81. and dragging around the borders of the graphic causes the graphic to spin in the plane of the screen. option name default value Axes AxesLabel True None BaseStyle Boxed FaceGrids LabelStyle Lighting Mesh PlotRange SphericalRegion ViewAngle ViewCenter ViewPoint ViewVector ViewVertical BoundaryStyle ClippingStyle ColorFunction Filling 8< True None 8< Automatic Automatic 9Full. Dragging the graphic while holding down the Shift key causes the graphic to pan.1< Automatic Automatic Automatic None whether to include axes labels to be put on the axes: zlabel specifies a label for the z axis.1.4. There are many options for threedimensional plots in Mathematica. 8xlabel.2< Automatic 80.
In[3]:= Plot3D@Sin@x yD. 0. 0.5<.0. . This redraws the previous plot with options changed. . PlotRange > 8.5<D Out[2]= The ClippingStyle option of Plot3D can be used to fill in the clipped regions. The first set can also be used in Show . PlotPoints > 50D Out[4]= . GrayD<D Out[3]= When you make the original plot. 3<. With this setting for PlotRange. 0. 0. ny = specifies different numbers in the x and y directions graphics directives for the style of each surface PlotStyle Automatic Some options for Plot3D. 8x. adding points for large variations. In[2]:= Show@%.0. 8y.5 § z § 0. 9nx . 3<.5 is shown.5.5.5D 25 style to use for filling the number of points in each direction at which to sample the function. Mathematica adaptively samples the plot. PlotRange > 8. 8x.9. only the part of the surface in the range 0. 10<.10. but occasionally you may still need to specify a greater number of points. 10<.10. you can choose to sample more points. In[4]:= Plot3D@10 Sin@x + Sin@yDD. 8y.18 Visualization and Graphics FillingStyle PlotPoints Opacity@. ClippingStyle Ø 8Opacity@.
In[5]:= Show@%. 0. AxesLabel > 8"Time". 8y.Visualization and Graphics 19 Here is the same plot. 8x. and grids added to each face. you are adjusting the ViewPoint value. ViewPoint > 80. viewed from the default view point 81. .2. . This view point is chosen to be “generic”. 3<. "Depth".2. so that visually confusing coincidental alignments between different parts of your object are unlikely. Notice the perspective effect that makes the back of the box look much smaller than the front. In[6]:= Plot3D@Sin@x yD. In[7]:= Show@%. FaceGrids > AllD Out[5]= Probably the single most important issue in plotting a threedimensional surface is specifying where you want to look at the surface from.3. 2<. Here is a surface. y. "Value"<. with labels for the axes. The ViewPoint option for Plot3D and Show allows you to specify the point 8x.4. When rotating a graphic using the mouse. The details of how the coordinates for this point are defined are discussed in "Coordinate Systems for ThreeDimensional Graphics". 3<D Out[6]= This redraws the picture. z< in space from which you view a surface. 0<D Out[7]= . with the view point directly in front. 0.
Having a box explicitly drawn around the surface is helpful in recognizing the orientation of the surface. along the positive z direction below. along the positive x direction The human visual system is not particularly good at understanding complicated mathematical surfaces. ViewPoint Ø AboveD Out[8]= 81. along the positive y direction above. As a result. you need to generate pictures that contain as many clues as possible about the form of the surface.20 Visualization and Graphics The ViewPoint option also accepts various symbolic values which represent common view points.4. along the negative z direction left. default view point in front.2< Front Back Above Below Left Right Typical choices for the ViewPoint option. . In[8]:= Show@%.2. along the negative x direction right. along the negative y direction in back. It is generally a good idea to keep the view point close enough to the surface that there is some perspective effect. View points slightly above the surface usually work best.3.
8y. 0. 8x. 3<.Hx ^ 2 + y ^ 2LD. For example. Mathematica assumes that there are four point light sources plus ambient lighting shining on the object.2. 2<. and how you can specify the reflection properties of an object.2. and so can be faithfully reproduced on a black and white output device such as a printer. In the default case. In[10]:= Plot3D@Exp@. 8x.2. 2<. 8y. 0.Hx ^ 2 + y ^ 2LD. . Mesh Ø NoneD Out[10]= To add an extra element of realism to threedimensional graphics.Visualization and Graphics 21 Here is a plot with the default settings for surface rendering options. 2<. Lighting can also be specified using a string which represents a collection of lighting properties. "Lighting and Surface Properties" describes how you can set up other light sources. 8x. It is usually much harder to see the form of the surface if the mesh is not there. 8y. the option setting Lighting > "Neutral" uses a set of white lights. In[11]:= Plot3D@8Sin@x yD<. 3<. Lighting Ø "Neutral"D Out[11]= . 2<D Out[9]= This shows the surface without the mesh drawn. . Mathematica by default colors threedimensional surfaces using a simulated lighting model. .2. In[9]:= Plot3D@Exp@. .
… join the points with lines ListPlot@8y1 .y2 <.…<. 3<. 49. and it builds up a curve or surface by evaluating the function at many different points. 9.…<D ListPlot@88x1 . ("Importing and Exporting Data" discusses how to read data from external files and programs. 8i. 2. instead of functions.z1 <. 81. 4. 100< .…<D make a threedimensional plot of the array of heights zyx ListPlot3D@88x1 . Here is a list of values. 25. 0.22 Visualization and Graphics The ColorFunction option by default uses Lighting > "Neutral" so that the surface colors are not distorted by colored lights. 8y. ColorFunction Ø HueD Out[12]= Plotting Lists of Data Mathematica can be used to make plots of functions. 8x. 16. y2 . Here we describe how you can make plots from lists of data. … plot points Hx1 . 0.8x2 . You give Mathematica a function. 36.8z21 . plot y1 .z12 .y2 .z2 <. yi < ListContourPlot@arrayD ListDensityPlot@arrayD Functions for plotting lists of data.…<E ListLinePlot@listD ListPlot3D@88z11 .y1 .) The Mathematica commands for plotting lists of data are direct analogs of the ones for plotting functions. 3<. In[1]:= make a contour plot make a density plot t = Table@i ^ 2. y1 L.z22 .y2 . … at x values 1.…<.8x2 .y1 <. In[12]:= Plot3D@8Sin@x yD<. 64. 10<D Out[1]= 81.…<D make a threedimensional plot with heights zi at positions 8xi .
5<. 8100. Mathematica chooses a different color for each dataset automatically. 4 i ^ 2 + i ^ 3<. In[4]:= ListPlot@8t. 825. 128<. 8i. 816.Visualization and Graphics 23 This plots the values. 63<. 360<. y pairs. In[2]:= ListPlot@tD 100 80 60 Out[2]= 40 20 2 4 6 8 10 This joins the points with lines. In[3]:= ListLinePlot@tD 100 80 60 Out[3]= 40 20 2 4 6 8 10 When plotting multiple datasets. 539<. . 10<D 836. 225<. 768<. 89. 2 t<D 200 150 Out[4]= 100 50 2 4 6 8 10 This gives a list of x. In[5]:= Table@8i ^ 2. 881. 1400<< Out[5]= 881. 24<. 849. 864. 84. 1053<.
In[6]:= ListPlot@%D 1400 1200 1000 Out[6]= 800 600 400 200 20 40 60 80 100 This gives a rectangular array of values. The array is quite large. 8y. 30<. so we end the input with a semicolon to stop the result from being printed out. In[8]:= ListPlot3D@t3D Out[8]= This gives a density plot of the array of values. In[9]:= ListDensityPlot@t3D Out[9]= . This makes a threedimensional plot of the array of values. 20<D.24 Visualization and Graphics This plots the points. In[7]:= t3 = Table@Mod@x. yD. 8x.
umax =E make a parametric plot of a threedimensional surface ParametricPlot3DA99 fx .umin . fz =.tmin .9gx .tmax =E make a parametric plot ParametricPlotA99 fx . fy .0 0. You can also use Mathematica to make parametric plots.5 0.0 0.gy . 0.9t.gz =.tmin .5 1. .9t.gy =.tmax =. Here is the curve made by taking the x coordinate of each point to be Sin@tD and the y coordinate to be Sin@2 tD.tmax =E plot several parametric curves together Functions for generating parametric plots.…=.9u. you give both the x and y coordinates of each point as a function of a third parameter. In a parametric plot.9gx . fy . fy . 8t.…E plot several objects together Threedimensional parametric plots. fz =.tmax =E make a parametric plot of a threedimensional curve ParametricPlot3DA9 fx .9t. fy =.…=. fy =. ParametricPlotA9 fx .0 0. In[1]:= ParametricPlot@8Sin@tD.tmin .0 ParametricPlot3DA9 fx . Sin@2 tD<.tmin .5 Out[1]= 1.Visualization and Graphics 25 Parametric Plots "Basic Plotting" described how to plot curves in Mathematica in which you give the y coordinate of each point as a function of the x coordinate. fz =. say t.5 1. 2 Pi<D 1.9t.
In[3]:= ParametricPlot3D@8u Sin@tD. With ParametricPlot. 0.5 1. 8u. u Cos@tD. fz <. 2 Pi<. tmin . 1<D Out[3]= . 8t. fy =. This makes a parametric plot of a helical curve.0 0. 8t. 0. then forms a curve by joining these points. tmin .5 1. 8t. tmax <E in two dimensions. it is in three dimensions. rather than a curve. t ê 3<.1. . The surface is formed from a collection of quadrilaterals. Here the x and y coordinates for the quadrilaterals are given simply by t and u. umin . fy . 8t. fy . the curve is in two dimensions. The result is a surface plot of the kind that can be produced by Plot3D.0 0. with ParametricPlot3D. In both cases. and linear motion in the z direction. 8t.0 4 Out[2]= 2 0 ParametricPlot3D@8 fx . 15<D 0.5 1. umax <D creates a surface.26 Visualization and Graphics ParametricPlot3D@8 fx . 8u.0 0. tmax <.0 0. Cos@tD. tmax <D is the direct analog in three dimensions of ParametricPlotA9 fx . Varying t produces circular motion in the xy plane.5 1. In[2]:= ParametricPlot3D@8Sin@tD.0 0. u<. The corners of the quadrilaterals have coordinates corresponding to the values of the fi when t and u take on values in a regular grid. tmin . fz <. Mathematica effectively generates a sequence of points by varying the parameter t.
u ^ 2 Cos@tD.1. . In each case. u Cos@tD. you can think of the surfaces as being formed by “distorting” or “rolling up” the tu coordinate grid in a certain way. In[5]:= ParametricPlot3D@8u Sin@tD. 15<. 0. it is possible to construct many complicated surfaces using ParametricPlot3D. 8u.1. 2 Pi<. but with the y coordinates distorted by a quadratic transformation. 8t. and at each section of the curve drawing a quadrilateral. u<. 8t. 0. In[4]:= ParametricPlot3D@8u Sin@tD. . t ê 3<. 1<D Out[4]= This produces a helicoid surface by taking the helical curve shown above.Visualization and Graphics 27 This shows the same surface as before. 1<D Out[5]= In general. . 8u.
You should be careful. 2 Pi<. Varying the t parameter yields a circle in the xy plane. 8u. Pi ê 2<D Out[8]= You should realize that when you draw surfaces with ParametricPlot3D. 0. 8t. u<. to avoid parametrizations . Cos@tD. In[6]:= ParametricPlot3D@8Sin@tD. 8u. Varying u yields a circle. 2 Pi<. Sin@uD<. 8t. Sin@tD Cos@uD.28 Visualization and Graphics This produces a cylinder. the exact choice of parametrization is often crucial. 8u. 0. 0. 2<D Out[6]= This produces a torus. .Pi ê 2. 0. 8t. 0. In[8]:= ParametricPlot3D@8Cos@tD Cos@uD. 2 Pi<. while varying u moves the circles in the z direction. while varying t rotates the circle around the z axis to form the torus. 2 Pi<D Out[7]= This produces a sphere. In[7]:= ParametricPlot3D@ 8Cos@tD H3 + Cos@uDL. Sin@tD H3 + Cos@uDL. Sin@uD<. for example.
The second group of functions are defined in standard Mathematica packages. This generates a loglinear plot. A few of the common ones are included in standard Mathematica packages.min.xD + 4 Exp@.xmin .…<D PieChart@listD plot a list of data as a bar chart generate a plot with error bars plot a list of data as a pie chart Some special plotting functions. 0.xmax <D LogLinearPlot@ f .max<D generate a threedimensional spherical plot BarChart@listD ErrorListPlot@88x1 . and may make ParametricPlot3D take much longer to render the surface.Visualization and Graphics 29 in which all or part of your surface is covered more than once.01 1 2 3 4 5 6 . Mathematica includes a full graphics programming language.y1 .8x.8x.xmax <D LogLogPlot@ f . 6<D 1 Out[1]= 0.2 xD.xmin .8x. 8x.dy1 <.8phi. In this language.1 0. generate a linearlog plot generate a loglinear plot generate a loglog plot generate a linearlog plot from a list of data generate a loglinear plot from a list of data generate a loglog plot from a list of data generate a polar plot of the radius r as a function of angle t LogPlot@ f . you can set up many different kinds of plots.min.xmin .8theta.tmin .tmax <D SphericalPlot3D@r.8t. Such multiple coverings often lead to discontinuities in the mesh drawn on the surface. In[1]:= LogPlot@Exp@.xmax <D ListLogPlot @listD ListLogLinearPlot@listD ListLogLogPlot@listD PolarPlot@r. Some Special Plots As discussed in "The Structure of Graphics and Sound".max<.
17. 29< Here is a bar chart of the primes. 19. 5. 3. 13. In[5]:= In[6]:= Needs@"PieCharts`"D PieChart@pD 6 5 7 4 3 2 1 8 Out[6]= 10 9 . 8n. 23. In[2]:= p = Table@Prime@nD. 7. In[3]:= In[4]:= Needs@"BarCharts`"D BarChart@pD Out[4]= This gives a pie chart. 11.30 Visualization and Graphics Here is a list of the first 10 primes. 10<D Out[2]= 82.
8x. it is always the instantaneous signal as a function of time. Mathematica can produce not only graphics but also sound. in Mathematica. This plays a more complex sound. 8t. 1<D Out[1]= Sounds produced by Play can have any waveform. 4<D Out[2]= . have to consist of a collection of harmonic pieces. 0. In[2]:= Play@Sin@700 t + 25 t Sin@350 tDD. 8t.Visualization and Graphics 31 Sound On most computer systems. Mathematica treats graphics and sound in a closely analogous way. They do not. and ultimately to a displacement. xmax <D to plot a function. Play takes the function to define the waveform for a sound: the values of the function give the amplitude of the sound as a function of time. 0. For example. so also you can use Play@ f . This signal is typically converted to a voltage. Note that amplitude is sometimes defined to be the peak signal associated with a sound. In[1]:= Play@Sin@2 Pi 440 tD. In general. play a sound with amplitude f as a function of time t in seconds Play@ f . for example. On a suitable computer system. tmax <D to “play” a function.tmax <D Playing a function.8t. this plays a pure tone with a frequency of 440 hertz for one second. 0. the amplitude function you give to Play specifies the instantaneous signal associated with the sound. just as you can use Plot@ f .0. 8t. xmin .
a2 . PlayA f . only a certain range of amplitudes is allowed. the better highfrequency components in the sound will be rendered. the higher the sample rate. f2 . The effective sample rate in a typical telephone system is around 8000. ListPlayA8a1 . The settings for this option are analogous to those for the PlotRange graphics option discussed in "Options for Graphics". In general.32 Visualization and Graphics Play is set up so that the time variable that appears in it is always measured in absolute seconds. the default sample rate used by Mathematica is around 8000. sampling it r times a second Specifying the sample rate for a sound. You can use Play@8 f1 . The fundamental frequencies for the 88 notes on a piano range from 27.…<. The function ListPlay allows you simply to give a list of values which are taken to be sound amplitudes sampled at a certain rate. The standard sample rate used for compact disc players is 44100. When a sound is actually played.SampleRate>rE play a sound with a sequence of amplitude levels Playing sampled sounds. .tmax =. In general.9t. On most computer systems. Mathematica supports any number of sound channels.0.SampleRate>rE play a sound. A sample rate of r typically allows frequencies up to r ê 2 hertz. The human auditory system can typically perceive sounds in the frequency range 20 to 22000 hertz (depending somewhat on age and sex). You can specify the sample rate by setting the option SampleRate. …D to produce stereo sound.5 to 4096 hertz. The option PlayRange in Play and ListPlay specifies how the amplitudes you give should be scaled to fit in the allowed range. When sounds are actually rendered by Mathematica. its amplitude is sampled a certain number of times every second.
and clip others Specifying the scaling of sound amplitudes. Line and Polygon. you should realize that Play may run significantly faster if you give an explicit PlayRange specification. The basic idea is that Mathematica represents all graphics in terms of a collection of graphics primitives. The primitives are objects like Point. The internal structure of Sound objects is discussed in "The Representation of Sound". emit a sound when evaluated EmitSound@sndD Playing sounds programmatically. While it is often convenient to use the setting PlayRange > Automatic. we discuss how Mathematica represents such graphics. In fact. Sounds can be played without the need for user intervention or producing output by using EmitSound. as well as directives such as RGBColor and Thickness. so it does not have to derive one.Visualization and Graphics 33 PlayRange>Automatic PlayRange>All PlayRange>8amin .amax < use an internal procedure to scale amplitudes scale so that all amplitudes fit in the allowed range make amplitudes between amin and amax fit in the allowed range. the internal implementation of Sound buttons uses EmitSound when the button is pressed. and how you can program Mathematica to create more complicated images. A Sound object in output is typically formatted as a button which contains a visualization of the sound and which plays the sound when pressed. The Structure of Graphics and Sound The Structure of Graphics "Graphics and Sound" discusses how to use functions like Plot and ListPlot to plot graphs of functions and data. that represent elements of a graphical image. . Here.
6..}.34 Visualization and Graphics This generates a plot of a list of points.. {19. 0.}.67.. There are several different kinds of graphics object.. {13.}}. 11. Each complete piece of graphics in Mathematica is represented as a graphics object. {18.. {17. you can use all the standard Mathematica functions to manipulate them. Axes > True. general twodimensional graphics general threedimensional graphics Graphics@listD Graphics3D@listD Graphics objects in Mathematica. 71.}. All the various graphics options used in this case are also given.. {12. In[1]:= ListPlot@Table@Prime@nD. {5.}. 71.}. 17. {20. Graphics objects are automatically formatted by the Mathematica front end as graphics upon output.}..}}]}. 59. {0.}. {}}}.}. {11. 47. Point[{{1.}. Each kind of graphics object has a definite head which identifies its type. 0}. {8.. 8n. 3. AxesOrigin > {0.}. {16.02]}}] Out[2]//InputForm= Graphics[{{{}.. Each point is represented as a coordinate in a Point graphics primitive. {AspectRatio > GoldenRatio^(1).. {4. PlotRangePadding > {Scaled[0.}. 43. {6. 5. 19. {9.}..}. Since graphics objects in Mathematica are just symbolic expressions.}. {15. 0. 2. You can create other kinds of graphical images in Mathematica by building up your own graphics objects. 61... 41..}.}.6].}. {14. Scaled[0. 67. 29. {Hue[0.}.. 7. . {10.. 53.. PlotRangeClipping > True.02]. corresponding to different types of graphics. 31. {7. 20.}. 13. and then displaying them.}. 20<DD 70 60 50 Out[1]= 40 30 20 10 5 10 15 20 InputForm shows how Mathematica represents the graphics. {3. 23.. The functions like Plot and ListPlot discussed in "The Structure of Graphics and Sound" all work by building up Mathematica graphics objects. PlotRange > {{0.... In[2]:= InputForm@%D {2. 37.. Graphics may also be printed as a side effect using the Print command.
Background Ø PinkD 1. 2 Pi<D. 0. 8x. optsD Show@g1 . It has no Out@D label because it is a side effect.5 Out[8]= 0.…. 2+2 Out[4]= 4 Show@g.0 . In[5]:= g1 = Plot@Sin@xD.5 1 2 3 4 5 6 1.optsD Displaying graphics objects. display a graphics object with new options specified by opts display several graphics objects combined using the options from g1 display several graphics objects with new options specified by opts Show can be used to change the options of an existing graphic or to combine multiple graphics.0 0.g2 .g2 . This uses Show to adjust the Background option of an existing graphic.…D Show@g1 . 2+2 Out[3]= 4 A side effect output can be generated using the Print command. Show@g1. In[4]:= Print@Graphics@Circle@DDD. In[3]:= Graphics@Circle@DD. but its output is suppressed by the semicolon.Visualization and Graphics 35 The Graphics object is computed by Mathematica.
36
Visualization and Graphics
This uses Show to combine two graphics. The values used for PlotRange and other options are based upon those which were set for the first graphic.
In[6]:=
Show@8g1, Graphics@Circle@DD<D
1.0
0.5
Out[9]=
1 0.5
1
2
3
4
5
6
1.0
Here, new options are specified for the entire graphic.
In[7]:=
Show@8g1, Graphics@Circle@DD<, PlotRange Ø All, AspectRatio Ø AutomaticD
1.0 0.5
Out[10]=
1 0.5 1.0
1
2
3
4
5
6
Graphics directives Graphics options
Local and global ways to modify graphics.
Examples: RGBColor , Thickness Examples: PlotRange, Ticks , AspectRatio ,
ViewPoint
Given a particular list of graphics primitives, Mathematica provides two basic mechanisms for modifying the final form of graphics you get. First, you can insert into the list of graphics primitives certain graphics directives, such as RGBColor, which modify the subsequent graphical elements in the list. In this way, you can specify how a particular set of graphical elements should be rendered.
This creates a twodimensional graphics object that contains the Polygon graphics primitive.
In[8]:=
poly = Polygon@Table@N@8Cos@n Pi ê 5D, Sin@n Pi ê 5D<D, 8n, 0, 5<DD; Graphics@polyD
Out[8]=
Visualization and Graphics
37
InputForm shows the complete graphics object.
In[9]:=
InputForm@%D
0.5877852522924731}, 0.9510565162951535}, 0.9510565162951535}, 0.5877852522924731}, {0.30901699437494745, {0.30901699437494745, {0.8090169943749475, {1., 0.}}]]
Out[9]//InputForm= Graphics[Polygon[{{1., 0.}, {0.8090169943749475,
This takes the graphics primitive created above, and adds the graphics directives RGBColor and EdgeForm .
In[10]:=
Graphics@8RGBColor@0.3, 0.5, 1D, EdgeForm@Thickness@0.01DD, poly<D
Out[10]=
By inserting graphics directives, you can specify how particular graphical elements should be rendered. Often, however, you want to make global modifications to the way a whole graphics object is rendered. You can do this using graphics options.
By adding the graphics option Frame you can modify the overall appearance of the graphics.
In[11]:=
Show@%, Frame > TrueD
0.8 0.6
Out[11]= 0.4
0.2 0.0 1.0 0.5 0.0 0.5 1.0
InputForm shows that the option was introduced into the resulting Graphics object.
In[12]:=
InputForm@%D
EdgeForm[Thickness[0.01]], Polygon[{{1., 0.}, {0.8090169943749475, 0.5877852522924731}, {0.30901699437494745, 0.9510565162951535}, {0.30901699437494745, 0.9510565162951535}, {0.8090169943749475, 0.5877852522924731}, {1., 0.}}]}, {Frame > True}]
Out[12]//InputForm= Graphics[{RGBColor[0.3, 0.5, 1],
38
Visualization and Graphics
You can specify graphics options in Show. As a result, it is straightforward to take a single graphics object, and show it with many different choices of graphics options. Notice however that Show always returns the graphics objects it has displayed. If you specify graphics options in Show, then these options are automatically inserted into the graphics objects that Show returns. As a result, if you call Show again on the same objects, the same graphics options will be used, unless you explicitly specify other ones. Note that in all cases new options you specify will overwrite ones already there.
give a list of all graphics options for a graphics object give the setting for a particular option
Options@gD Options@g,optD
Finding the options for a graphics object.
Some graphics options can be used as options to visualization functions which generate graphics. Options which can take the righthand side of Automatic are sometimes resolved into specific values by the visualization functions.
Here is a plot.
In[13]:=
zplot = Plot@Abs@Zeta@1 ê 2 + I xDD, 8x, 0, 10<, PlotRange Ø AutomaticD
1.4 1.2
Out[13]=
1.0 0.8
2
4
6
8
10
Mathematica uses an internal algorithm to compute an explicit value for PlotRange in the resulting graphic.
In[14]:=
Options@zplot, PlotRangeD
Out[14]= 8PlotRange Ø 880., 10.<, 80.526253, 1.54919<<<
FullGraphics@gD
translate objects specified by graphics options into lists of explicit graphics primitives
Finding the complete form of a piece of graphics.
When you use a graphics option such as Axes, the Mathematica front end automatically draws objects such as axes that you have requested. The objects are represented merely by the
Visualization and Graphics
39
option values rather than by a specific list of graphics primitives. Sometimes, however, you may find it useful to represent these objects as the equivalent list of graphics primitives. The function FullGraphics gives the complete list of graphics primitives needed to generate a particular plot, without any options being used.
This plots a list of values.
In[15]:=
ListPlot@Table@EulerPhi@nD, 8n, 10<DD
6 5 4
Out[15]=
3 2 2 4 6 8 10
FullGraphics yields a graphics object that includes graphics primitives representing axes and
so on.
In[16]:=
Short@InputForm@FullGraphics@%DD, 6D
Graphics@8888<, 8Hue@0.67, 0.6, 0.6D, Point@881., 1.<, 82., 1.<, 83., 2.<, 84., 2.<, 85., 4.<, 86., 2.<, 87., 6.<, 88., 4.<, 89., 6.<, 810., 4.<<D<, 8<<<, 88GrayLevel@0.D, AbsoluteThickness@0.25D, Line@882., 1.<, 82., 1.0505635621484342<<D<, <<56>><<D
Out[16]//Short=
TwoDimensional Graphics Elements
Point@8x,y<D Line@88x1 ,y1 <,8x2 ,y2 <,…<D Rectangle@8xmin ,ymin <,8xmax ,ymax <D Polygon@88x1 ,y1 <,8x2 ,y2 <,…<D Circle@8x,y<,rD Disk@8x,y<,rD Raster@88a11 ,a12 ,…<,8a21 ,…<,…<E Text@expr,8x,y<D
Basic twodimensional graphics elements. Here is a line primitive.
In[1]:=
point at position x, y line through the points 8x1 , y1 <, 8x2 , y2 <, … filled rectangle filled polygon with the specified list of corners circle with radius r centered at x, y filled disk with radius r centered at x, y rectangular array of gray levels between 0 and 1 the text of expr, centered at x, y (see "Graphics Primitives for Text")
sawline = Line@Table@8n, H 1L ^ n<, 8n, 6<DD
Out[1]= Line@881, 1<, 82, 1<, 83, 1<, 84, 1<, 85, 1<, 86, 1<<D
40
Visualization and Graphics
This shows the line as a twodimensional graphics object.
In[2]:=
sawgraph = Graphics@sawlineD
Out[2]=
This redisplays the line, with axes added.
In[3]:=
Show@%, Axes > TrueD
1.0 0.5
Out[3]=
0.5 1.0
2
3
4
5
6
You can combine graphics objects that you have created explicitly from graphics primitives with ones that are produced by functions like Plot.
This produces an ordinary Mathematica plot.
In[4]:=
Plot@Sin@Pi xD, 8x, 0, 6<D
1.0
0.5
Out[4]=
1 0.5
2
3
4
5
6
1.0
This combines the plot with the sawtooth picture made above.
In[5]:=
Show@%, sawgraphD
1.0
0.5
Out[5]=
0.5
1
2
3
4
5
6
1.0
Visualization and Graphics
41
You can combine different graphical elements simply by giving them in a list. In twodimensional graphics, Mathematica will render the elements in exactly the order you give them. Later elements are therefore effectively drawn on top of earlier ones.
Here are two blue Rectangle graphics elements.
In[6]:=
8Blue, Rectangle@81,  1<, 82,  0.6<D, Rectangle@84, .3<, 85, .8<D<
Out[6]= 8RGBColor@0, 0, 1D, Rectangle@81, 1<, 82, 0.6<D, Rectangle@84, 0.3<, 85, 0.8<D<
This draws the rectangles on top of the line that was defined above.
In[7]:=
Graphics@8sawline, %<D
Out[7]=
The Polygon graphics primitive takes a list of x, y coordinates, corresponding to the corners of a polygon. Mathematica joins the last corner with the first one, and then fills the resulting area.
Here are the coordinates of the corners of a regular pentagon.
In[8]:=
pentagon = Table@8Sin@2 Pi n ê 5D, Cos@2 Pi n ê 5D<, 8n, 5<D
5 8 5 8 5 8 5 8 1 4 1 4 5 8 5 8 5 8 5 8 1 4 1 4
Out[8]= ::
+
,
1 +
5
>, :

,
1 
5
>,
:

,
1 
5
>, :
+
,
1 +
5
>, 80, 1<>
This displays the pentagon. With the default choice of aspect ratio, the pentagon looks somewhat squashed.
In[9]:=
Graphics@Polygon@pentagonDD
Out[9]=
y<. y< an ellipse with semiaxes rx and ry a circular arc an elliptical arc filled disks .line2 . a circle with radius r centered at the point 8x.theta2 <D CircleA 9x. a large number of lines or polygons can be represented as a list of coordinate lists. pt2 .rD CircleA9x.y=.y=. … a multipolygon consisting of polygons poly1 .5 + .0 2 4 6 Out[11]= Circle@8x.5 pentagon.ry =.r. … Primitives which can take multiple elements. Axes Ø TrueD 1.6. 1.theta2 <E DiskA9x.y=. Similarly. This representation is efficient and can generally be rendered more quickly by the Mathematica front end.poly2 .y<.2<DD<. This creates a multipolygon based upon the set of coordinates defined previously.9rx . In[10]:= Graphics@Polygon@8pentagon. 6. Point@Table@8x.…<D Polygon@8poly1 .9rx . Circles and disks.8theta1 . Graphics directives such as RGBColor apply uniformly to the entire set of primitives. 8x. etc.5 6 4 2 0. A large number of points can be represented by putting a list of coordinates inside of a single Point primitive. … a multiline consisting of lines line1 . 1 + .0 0.42 Visualization and Graphics Point@8pt1 .…<D Line@8line1 . In[11]:= Graphics@8Blue.pt2 .5 1.…<D a multipoint consisting of points at pt1 .rE .ry =E Circle@8x. Cos@xD<. .2 pentagon<DD Out[10]= Here is a multipoint which is colored blue. .8theta1 . poly2 . line2 .
a12 . … }. Circle@81. 8n ê 4.o11 <. This draws a 140È wedge centered at the origin. 0<. 1.…<D array of gray levels between 0 and 1 array of gray levels with opacity between 0 and 1 . 2D. In[12]:= Graphics@8Circle@80.9a21 . … }] Raster@888a11 . 0<.n ê 4<D.Visualization and Graphics 43 This shows two circles with radius 2. 0<. and progressively smaller ones in the y direction. and segments of ellipses. 8n. The angles are measured counterclockwise in radians with zero corresponding to the positive x direction. In both cases.…<. 2 . the objects are specified by starting and finishing angles. 2D<D Out[12]= This shows a sequence of disks with progressively larger semiaxes in the x direction. 4<DD Out[13]= Mathematica allows you to generate arcs of circles. In[13]:= Graphics@Table@Disk@83 n. 1<. In[14]:= Graphics@Disk@80. 80. 140 Degree<DD Out[14]= RasterA 98a11 .…<.
0. 0. 0.44 Visualization and Graphics Raster@888r11 .333333<.. 8i.333333. 0. 4<D êê N 80.b11 <.<.…<. 0.333333. This uses the array of values as gray levels in a raster.88xmin .333333. ymax < Raster@888r11 . 2<<D.g11 . 0<. 80.8zmin .666667<. 0.zmax <D Rasterbased graphics elements.333333. jD ê 3.<< Out[15]= 880. 82. 83. ColorFunction Ø HueD<D Out[18]= . Raster@modtab.b11 ..o11 <. In[16]:= Graphics@Raster@modtabDD Out[16]= This shows two overlapping copies of the raster.. 0. 0.g11 . In[18]:= Graphics@8Raster@modtab.5<..…<D Raster@array. 0. ymin < and 8xmax . 8j.. 1. 1. In[15]:= modtab = Table@Mod@i... 881.666667. 2<<D<D Out[17]= The ColorFunction option can be used to change the default way in which a Raster is colored. 8xmax . array of rgb values between 0 and 1 array of gray levels between zmin and zmax drawn in the rectangle defined by 8xmin .ymin <. In[17]:= Graphics@8Raster@modtab. 880.…<. 4<. 0.…<D array of rgb values with opacity between 0 and 1 Here is a 4×4 array of values between 0 and 1.5. 80.ymax <<. 0.
In[2]:= Graphics@%D Out[2]= GrayLevel@iD RGBColor@r. Rectangle@80. the graphical elements in a particular graphics object can be given in a collection of nested lists. you typically give a list of graphical elements. The graphics directive does not. 1<. Rectangle@81. 0<. In general. saturation and brightness.bD Basic Mathematica color specifications. 1<D<. In[1]:= 88GrayLevel@0. 81.5D. Rectangle@80. gray level between 0 (black) and 1 (white) color with specified red. 1<D<. each between 0 and 1 color with hue h between 0 and 1 color with specified hue. 2<D< Out[1]= 88GrayLevel@0. have any effect outside the list it is in. however.5D. together with all elements of sublists that may occur. Rectangle@81. You can include in that list graphics directives which specify how subsequent elements in the list should be rendered. 2<D< Only the rectangle in the first sublist is affected by the GrayLevel directive.g. The first sublist contains the graphics directive GrayLevel. the rule is that a particular graphics directive affects all subsequent elements of the list it is in. 0<. 1<. When you insert graphics directives in this kind of structure. green and blue components. 81.bD Hue@hD Hue@h. each between 0 and 1 .Visualization and Graphics 45 Graphics Directives and Options When you set up a graphics object in Mathematica. 82. 82.s.
1D<<D 25 20 15 Out[3]= 10 5 1 2 3 4 5 The function Hue@hD provides a convenient way to specify a range of colors using just one parameter. the diameter d is measured as a fraction of the width of your whole plot. decreasing the saturation toward zero leads to progressively more “washed out” colors. such as Red. Gray. bD allows you to specify not only the “hue”. 8x. Hue@h. it affects all subsequent graphical elements that appear in a particular list. Hue@hD runs through red. xD<. which allows you to specify the “absolute” diameter of points. . The graphics directive PointSize@dD specifies that all Point elements which appear in a graphics object should be drawn as circles with diameter d.7. and back to red again. These color names. cyan. Mathematica also provides the graphics directive AbsolutePointSize@dD. PointSize@dD AbsolutePointSize@dD Graphics directives for points. yellow. green. but also the “saturation” and “brightness” of a color.46 Visualization and Graphics Mathematica accepts the names of many colors directly as color specifications.3. 5<. give all points a diameter d as a fraction of the width of the whole plot give all points a diameter d measured in absolute units 1 72 of an inch. xD. Mathematica also supports various graphics directives which affect only specific types of graphical elements. 0. LightGreen and Purple. magenta. s. The first plot is colored with a color name. are implemented as variables which evaluate to an RGBColor specification. In PointSize. PlotStyle > 88Red<. blue. As h varies from 0 to 1. 8RGBColor@0. 0. When you give a graphics directive such as RGBColor. BesselI@2. while the second one has a finetuned RGBColor specification. 0. In[3]:= Plot@8BesselI@1. Taking the saturation to be equal to one gives the deepest colors. The units are approximately printer’s points. The color names can be used interchangeably with color directives. measured in fixed units.
5<D. 0<. 1<<D<. 82. Line@880. 13<D< This makes each point have a diameter equal to onetenth of the width of the plot.…<D Graphics directives for lines. 0<. %<. Line@880. In[7]:= Table@8AbsoluteThickness@nD. 8n. Point@86. 2<D. PlotStyle > AbsolutePointSize@3DD 70 60 50 40 20 10 5 10 15 20 Out[6]= 30 Thickness@wD AbsoluteThickness@wD Dashing@8w1 . … use absolute units to measure dashed segments This generates a list of lines with different absolute thicknesses. 6<D Out[4]= 8Point@81. 81. 0<. 1<<D<. Point@84. 84. 8n. Line@880.Visualization and Graphics 47 Here is a list of points. In[5]:= Graphics@8PointSize@0. 8AbsoluteThickness@2D. 11<D. Line@880. 0<. w2 . 1<<D<. give all lines a thickness w as a fraction of the width of the whole plot give all lines a thickness w measured in absolute units show all lines as a sequence of dashed segments. 3<D.1D. 0<. PlotRange > AllD Out[5]= Here each point has size 3 in absolute units. 4<D 8AbsoluteThickness@3D.…<D AbsoluteDashing@8w1 . Point@83. 1<<D<. 7<D. Point@85. Point@82.w2 . with lengths w1 . Line@880. In[4]:= Table@Point@8n. 8AbsoluteThickness@4D. 20<D.w2 . Prime@nD<D. 1<<D<< Out[7]= 88AbsoluteThickness@1D. . 8n. 83. 8n. In[6]:= ListPlot@Table@Prime@nD.
Line@880. In[10]:= Graphics@8Dashing@80. Line@88. 83.05<D. 1<<D<D Out[9]= This gives a dotdashed line. Dashing is turned off for only the second line. Line@880. 1<<D<D Out[10]= Dashing can be turned off by specifying an empty list.48 Visualization and Graphics Here is a picture of the lines. 1<<D<. 0<. 1<<D<D Out[11]= . 82.05.05. . 81. In[11]:= Graphics@8Dashing@80. 0. This sequence is repeated as many times as necessary in drawing the whole line. 0<. Here. In[8]:= Graphics@%D Out[8]= The Dashing graphics directive allows you to create lines with various kinds of dashing. By changing the lengths of the segments.05.1<. This gives a dashed line with a succession of equallength segments.05<D.1<. Line@88. 0. 8Dashing@8<D. 0. you can get different line styles.1. 81. . In[9]:= Graphics@8Dashing@80. 81. Line@880. 0.01. The basic idea is to break lines into segments which are alternately drawn and omitted. 1<<D. 0<.1. Dashing allows you to specify a sequence of segment lengths.05<D.
This specifies a large thickness with medium dashing. 82.0 1 2 3 4 5 6 This specifies that the entire multipoint should use large. Point@880. .…< MeshStyle>style BoxStyle>style Some graphics options for specifying styles.. 8x. Thickness@LargeD<<D 1. however. these values have been finetuned to produce an appearance which will seem appropriate to the human eye.8style2 <. 0. Medium. specify a style to be used for all curves in Plot specify styles to be used (cyclically) for a sequence of curves in Plot specify a style to be used for a mesh in density and surface graphics specify a style to be used for the bounding box in threedimensional graphics PlotStyle>style PlotStyle>88style1 <.5<.5<<D<D Out[13]= One way to use Mathematica graphics directives is to insert them directly into the lists of graphics primitives used by graphics objects. 81. you want the graphics directives to be applied more globally. . Green. Small. and Large. Sometimes. green points. In[12]:= Plot@Sin@xD. For each directive. 2 Pi<. 0. PlotStyle Ø 88Dashing@8Medium<D.5 Out[12]= 0. There are typically graphics options which can be set to specify such styles in terms of lists of graphics directives.0 0. and for example to determine the overall “style” with which a particular type of graphical element should be rendered.Visualization and Graphics 49 Graphics directives which require a numerical size specification can also accept values of Tiny.5 1. 0<. In[13]:= Graphics@8PointSize@LargeD. 0<. 81.
0. 8x. This draws the plot in white on a gray background.4 Out[15]= 0.6 0. 10<. xD. xD. BesselJ@2.50 Visualization and Graphics This generates a plot in which all curves are specified to use the same style. xD<. xD<. Background Ø Gray. 0. Gray<<D 0.5 Out[16]= 2 0. 8Red<<D 0. 10<. In[16]:= Plot@Sin@Sin@xDD. Mathematica also provides options that affect the rendering of the whole plot.6 0.5 4 6 8 10 . 10<. Gray<. PlotStyle Ø WhiteD 0.02D. 8x.2 2 0. BesselJ@2. In[15]:= Plot@8BesselJ@1.2 4 6 8 10 A different PlotStyle expression can be used to give specific styles to each curve. 0. In[14]:= Plot@8BesselJ@1.4 Out[14]= 0. PlotStyle > 88Thickness@0. affecting elements not affected by PlotStyle give graphics to render before a plot is started give graphics to render after a plot is finished Background>color BaseStyle>color Prolog>g Epilog>g Graphics options that affect whole plots.02D. PlotStyle > 88Thickness@0. 8x.2 4 6 8 10 The various “style options” allow you to specify how particular graphical elements in a plot should be rendered.2 2 0. specify the background color for a plot specify the base style for a plot.
the range of original coordinates to include in the plot PlotRange>99xmin .5 4 6 8 10 Coordinate Systems for TwoDimensional Graphics When you set up a graphics object in Mathematica. one of the first things it has to do is to work out what range of original x and y coordinates it should actually display. 20<DD. the default setting is PlotRange > Automatic. which makes Mathematica try to choose a range which includes all "interesting" parts of a plot. When Mathematica renders the graphics object. You can also give explicit ranges of coordinates to include.5 Out[17]= 2 0. By setting PlotRange > All.05 H. . 8n.1L ^ n. while dropping "outliers". you can tell Mathematica to include everything. The option PlotRange specifies the range of original coordinates to include. BaseStyle Ø WhiteD 0. This sets up a polygonal object whose corners have coordinates between roughly ± 1. and not shown. you give coordinates for the various graphical elements that appear.Visualization and Graphics 51 This makes the axes white as well. When Mathematica renders a graphics object. Any graphical elements that are outside this range will be clipped.9ymin . it has to translate the original coordinates you gave into "display coordinates" which specify where each element should be placed in the final display area. Cos@n Pi ê 10D< + 0.ymax == Option which determines translation from original to display coordinates. As discussed in "Options for Graphics". In[17]:= Show@%. xmax =. In[1]:= obj = Polygon@Table@8Sin@n Pi ê 10D.
the polygonal object fills almost the whole display area. .52 Visualization and Graphics In this case. 1<. is what the final display area is like. In general. How it fits into this region is determined by its “shape” or aspect ratio. In[3]:= Graphics@obj. however. there is a certain fixed region of screen or paper into which the Mathematica display area must fit. In[2]:= Graphics@objD Out[2]= Specifying an explicit PlotRange allows you to zoom in on a section of a graphic. All<D Out[3]= AspectRatio >r AspectRatio >Automatic Specifying the shape of the display area. What remains to discuss. the option AspectRatio specifies the ratio of height to width for the final display area. PlotRange Ø 880. make the ratio of height to width for the display area equal to r determine the shape of the display area from the original coordinate system What we have discussed so far is how Mathematica translates the original coordinates you specify into positions in the final display area. On most computer systems.
In[4]:= Graphics@Polygon@Table@8Sin@n Pi ê 3D. These coordinates always run from 0 to 1 across the display area. In[5]:= Show@%. the aspect ratio of the final display area is determined from the original coordinate system. 6<DDD Out[4]= This renders the hexagon in a display area whose height is three times its width. objects that you define in the original coordinate system are displayed with their "natural shape". This generates a graphic object corresponding to a regular hexagon. This determines the aspect ratio from the original coordinate system used in the plot instead of setting it at a fixed value. With the default value of AspectRatio > Automatic. What AspectRatio does is to change the shape of this display area. 8n. AspectRatio > 3D Out[5]= . and the hexagon is shown with its "natural shape". In this way. Cos@n Pi ê 3D<. AspectRatio is set by default to Automatic. One unit in the x direction in the original coordinate system corresponds to the same distance in the final display as one unit in the y direction. For twodimensional graphics.Visualization and Graphics 53 It is important to note that the setting of AspectRatio does not affect the meaning of the scaled or display coordinates.
25.y< Scaled@8sx. The scaled coordinates are defined to run from 0 to 1 in x and y.75<DD<D 2 1 0 Out[7]= 1 2 2 1 0 1 2 x . The display area is significantly larger than the plot range due to the frame label. 0. In[7]:= Show@g. the rectangle falls at the origin. In[6]:= g = Graphics@8Green.25<D. sy<D rather than 8x. Disk@D<. which is at the center of the specified plot range. You can do this by using scaled coordinates Scaled@8sx. with the origin taken to be at the lowerleft corner of the plot range. LargeD<D 2 1 0 Out[6]= 1 2 2 1 0 1 2 x Using Scaled coordinates. Frame Ø True.75. Prolog Ø 8Rectangle@Scaled@80. PlotRange Ø 2.sy<D ImageScaled @8sx.54 Visualization and Graphics Sometimes. FrameLabel Ø 8Style@"x". y<. Scaled@80. original coordinates coordinates scaled to the plot range coordinates scaled to the display area 8x.sy<D Coordinate systems for twodimensional graphics. 0. you may find it convenient to specify the display coordinates for a graphical element directly.
the rectangle falls at exactly the center of the graphic. dsy<. Scaled@8sx. 8x. y<D to specify a position using a mixture of original and scaled coordinates. if you want to draw a line at a particular point whose length is a definite fraction of the width of the plot.Visualization and Graphics 55 Using ImageScaled coordinates. dsy< gives the offset from the position in scaled coordinates. For example. you may need to use a combination of these coordinate systems. Sometimes. which does not coincide with the center of the plot range. You can use Scaled@8dsx. y< gives a position in original coordinates. however. or completely in scaled coordinates. 0. and 8dsx. 0.25. and scaled coordinates to specify its length. you are specifying position either completely in original coordinates.25<D.y<.Scaled@sxDE DiskA8x. In this case. .y<. y<. sy<D.75. Prolog Ø 8Rectangle@ImageScaled@80. sy<D or ImageScaled @8sx. you will have to use original coordinates to specify the basic position of the line. In[8]:= Show@g.75<DD<D 2 1 0 Out[8]= 1 2 2 1 0 1 2 x When you use 8x. a circle whose radius is scaled to the width of the plot range a disk whose radius is scaled to the width of the plot range specification for a font size scaled to the width of the plot range CircleA8x. ImageScaled@80.Scaled@sxDE FontSize>Scaled@sxD Some places where Scaled can be used with a single argument. 8x.
8x.8x.3DD. Text@"some text". x ^ 2<. ImageScaled @8sx.sy<DD absolute offset from scaled coordinates absolute offset from image scaled coordinates Each line drawn here has an absolute length of 6 printer’s points. FontSize Ø Scaled@0. 8x. In[10]:= Graphics@Table@Line@88x. Offset@80. 80. Frame > TrueD 100 80 .8x.ady<.y<D OffsetA8adx.ady<.y<D Offset@8adx. 0<D<D Out[9]= some text Scaled@8sdx. 6<. 8x.Scaled@8sx. x ^ 2<D<D. 10<D.56 Visualization and Graphics Both the radius of the circle and the size of the font are specified in Scaled values. Scaled@0.sy<DE Positions specified as offsets.sdy<. 0<.ady<.2D.sdy<. scaled offset from original coordinates image scaled offset from original coordinates absolute offset from original coordinates Offset@8adx. In[9]:= Graphics@ 8Circle@80.y<D ImageScaled @8sdx.
Visualization and Graphics 57 60 Out[10]= 40 20 2 4 6 8 10 .
10<D. Frame > TrueD 100 80 60 Out[11]= 40 . In[11]:= Graphics@Table@Circle@8x. x ^ 2<. 8x.58 Visualization and Graphics You can also use Offset inside Circle with just one argument to create a circle with a certain absolute radius. Offset@82. 2<DD.
you can specify the sizes of graphical elements as fractions of the size of the display area. Of course. But sometimes you may instead want the offset from one object to another to be constrained to remain fixed. The units for the offset are printer’s points. You can use Offset to move text around in a plot. tell Mathematica the actual physical size at which a particular graphical element should be rendered. has letters whose basic height is 10 printer’s points. for example. a 10point font. this size ultimately depends on the details of your graphics output device. positionD allows you to specify the position of an object by giving an absolute offset from a position that is specified in original or scaled coordinates. you typically want the relative positions of different objects to adjust automatically when you change the coordinates or the overall size of your plot.Visualization and Graphics 59 20 2 4 6 8 10 In most kinds of graphics. for example. and to create plotting symbols or icons which match the size of the text. Therefore. Offset@8adx. When you give text in a plot. equal to 1 72 of an inch. when you are making a collection of plots in which you want certain features to remain consistent. This can be the case. even though the different plots have different forms. however. ady<. the size of the font that is used is also specified in printer’s points. and cannot be determined for certain within Mathemat . You cannot. Using scaled coordinates.
0 0.4 0.) Labeling TwoDimensional Graphics Axes>True GridLines>Automatic Frame>True PlotLabel>"text" Ways to label twodimensional plots. using the default Axes > True . it is neither possible nor desirable to maintain the same absolute size for a graphical element within it. Frame > TrueD 0. output devices. and removes tick marks from the ordinary axes. Here is a plot. but not all. graphics directives such as AbsoluteThickness discussed in "Graphics Directives and Options" do allow you to indicate “absolute sizes” to use for particular graphical elements. 0. xD.2 Out[1]= 2 0. if you optically project an image. 8x.2 4 6 8 10 Setting Frame > True generates a frame with axes. 10<D 0. Nevertheless.2 Out[2]= 0.60 Visualization and Graphics ica. The sizes you request in this way will be respected by most. (For example.2 0 2 4 6 8 10 . In[1]:= give a pair of axes draw grid lines on the plot put axes on a frame around the plot give an overall label for the plot bp = Plot@BesselJ@2.4 0. In[2]:= Show@bp.
GridLines > AutomaticD 0.y= AxesStyle>style AxesStyle>8xstyle.Visualization and Graphics 61 This includes grid lines. In[3]:= Show@%. draw no tick marks place tick marks automatically tick mark specifications for each axis . In[4]:= Show@bp.2 Out[3]= 0. which are shown in light gray.2 6 8 10 x 0. AxesLabel > 8"x". 0<.ylabel= Options for axes.yticks= Settings for the Ticks option. 0<. and puts a label on each axis. draw no axes draw both x and y axes draw a y axis but no x axis choose the crossing point for the axes automatically specify the crossing point specify the style for axes specify individual styles for axes give no axis labels put a label on the y axis put labels on both x and y axes This makes the axes cross at the point 85.0 0.4 0. "y"<D y 0.4 Out[4]= 0 2 4 0.True= AxesOrigin>Automatic AxesOrigin>9x.2 0 2 4 6 8 10 Axes>False Axes>True Axes>9False.2 Ticks>None Ticks>Automatic Ticks>9xticks.ystyle< AxesLabel>None AxesLabel>ylabel AxesLabel>9xlabel. AxesOrigin > 85.
""<. however. Pi. ""<.label2 <. xmax to get the tick mark option Tick mark options for each axis. Pi. You will need to do this. 2 Pi.…< func Show@bp.2 2p 3p This adds tick marks with no labels at multiples of p ê 2.8plen1 . 8Pi ê 2.…< 88x1 .mlen1 <<.4 0. or if you want to put a nonlinear scale on an axis. 2 Pi.label1 .x2 . In some cases.label1 <. draw no tick marks place tick marks automatically draw tick marks at the specified positions draw tick marks with the specified labels draw tick marks with the specified scaled lengths draw tick marks with the specified lengths in the positive and negative directions draw tick marks with the specified styles a function to be applied to xmin .style1 <.…< 88x1 . 3 Pi<. ""<. 3 Pi<. This gives tick marks at specified positions on the x axis. and chooses the tick marks automatically on the y axis.4 0. Mathematica creates a certain number of major and minor tick marks. and places them on axes at positions which yield the minimum number of decimal digits in the tick labels. Ticks > 880. 83 Pi ê 2. Ticks > 880. if you want to have tick marks at multiples of p.2 2p 3p .len1 . Automatic<D 0.2 Out[6]= p 0.…< 88x1 .len1 <.label1 .62 Visualization and Graphics With the default setting Ticks > Automatic. you may want to specify the positions and properties of tick marks explicitly. 85 Pi ê 2. Automatic<D 0. for example.8x2 . In[6]:= Show@bp.label1 .2 Out[5]= p 0.…< 88x1 . In[5]:= None Automatic 8x1 .
draw no frame draw a frame around the plot specify a style for the frame specify styles for each edge of the frame give no frame labels put labels on edges of the frame do not rotate text in labels draw no tick marks on frame edges position tick marks automatically specify tick marks for frame edges The Axes option allows you to draw a single pair of axes in a plot. Floor@xmaxD. corresponding to the four edges of the frame around a plot.8bottom.Visualization and Graphics 63 Particularly when you want to create complicated tick mark specifications. Ticks > 8units. This defines a function which gives a list of tick mark positions with a spacing of 1. In[7]:= units@xmin_. xmax_D := Range@Floor@xminD. however. you may instead want to show the scales for a plot on a frame. it is often convenient to define a "tick mark function" which creates the appropriate tick mark specification given the minimum and maximum values on a particular axis.2 Out[8]= 1 0.top<< RotateLabel >False FrameTicks>None FrameTicks>Automatic FrameTicks> 88left.top<< Options for frame axes. typically drawn around the whole plot.right<.right<. In[8]:= Show@bp. Automatic<D 0. Sometimes.top<< FrameLabel>None FrameLabel> 88left.8bottom.8bottom.right<. The option Frame allows you effectively to draw four axes. 1D This uses the units function to specify tick marks for the x axis. .2 2 3 4 5 6 7 8 9 10 Frame>False Frame>True FrameStyle>style FrameStyle> 88left.4 0.
draw no grid lines position grid lines automatically specify grid lines in analogy with tick marks Grid lines in Mathematica work very much like tick marks.0 0.2 0 2 4 6 bottom label 8 10 GridLines>None GridLines>Automatic GridLines>9xgrid. In[10]:= Show@bp.64 Visualization and Graphics This draws frame axes. you can specify a style. "top label"<<D top label 0. however. Frame > True. you can specify explicit positions for grid lines. you can combine and superimpose plots in any way. GridLines > 8Automatic.2 Out[10]= 2 0.4 0. None<D 0. There is no label or length to specify for grid lines. Using the Inset graphics primitive. and labels each of them.2 4 6 8 10 Insetting Objects in Graphics "Redrawing and Combining Plots" describes how you can make regular arrays of plots using GraphicsGrid.2 . FrameLabel > 88"left label". This generates x but not y grid lines. 8"bottom label".ygrid= Options for grid lines. right label left label 0. "right label"<.4 Out[9]= 0. As with tick marks. In[9]:= Show@bp. However.
0 1. Frame Ø True. 5<. 0. size. In[2]:= ParametricPlot@8Sin@xD.0 0. opos. Here is a plot.0 0.0 0.pos. Epilog Ø Inset@p1.5 1.5 1. opos. 8x. 8x. ImageSize Ø 200.0 0.5. Sin@2 xD<.5 Out[2]= 1.5<DD 1.0 1. 8x. . sizeD Inset@obj.0 0.0 0 1 2 3 4 5 6 This creates a plot within a parametric plot.5 1. 2 p<. Background Ø LightYellowD 1.Visualization and Graphics 65 Inset@obj. 4 p<. .5 Out[1]= 0.0 0. 2<D Out[3]= .0 0. 0. dirsD Creating an inset. posD Inset@obj. In[3]:= p3 = Plot3D@Sin@xD Exp@yD.3. 8y.5 0.5 Here is a threedimensional plot.pos.5 0. In[1]:= specifies that the inset should be placed at position pos in the graphic render an object with a given size so that point opos in obj is positioned at point pos in the containing graphic specifies that the axes of the inset should be oriented in directions dirs p1 = Plot@8Sin@xD.. . Sin@2 xD<.2. 8.
1<<D <D Out[5]= 1. cells. 881. In[5]:= Graphics@8 Inset@p1.5<. 81. . PlotRange Ø 2D Out[4]= Here are rotated and skewed plots inset in a graphic. In[4]:= Graphics@8Inset@p3. 82. 81.5. 81. 3<D<. 1<. Center. 0<. 82.0 0 1 2 3 5 6 4 4 5 6 Mathematica can render plots. 8. 0<. 5 3 0.0 0.5 1. Inset@p3.5 . 81. 0 2 1. arbitrary 2D or 3D graphics.66 Visualization and Graphics This creates a twodimensional graphics object that contains two differently sized copies of the threedimensional plot. Center. 1<D.81. 81. 83. and text within an Inset. 1<. . Inset@p1.5 0. 0 1 . Center.0 0 1 . 0 0. 2<D. 0<. 1<. Notice that in general the display area for graphics objects will be sized so as to touch at least one pair of edges of the Inset. Center.0 0.
.8x.ymax <D make a contour plot of f as a function of x and y Density and contour plots.8x. Automatic None Automatic Automatic what colors to use for shading.xmax <. .ymax <D make a density plot of f ContourPlot @ f .xmax <.8y.8y. In[1]:= DensityPlot@Sin@xD Sin@yD.2. 2<D Out[1]= option name default value ColorFunction Mesh PlotPoints MaxRecursion Some options for DensityPlot .xmin .xmin .Visualization and Graphics 67 Density and Contour Plots DensityPlot @ f . 8x. Hue uses a sequence of hues whether to draw a mesh number of initial sample points in each direction the maximum number of recursive subdivi sion steps to do .ymin .2. 2<. This gives a density plot of sinHxL sinHyL. 8y. Lighter regions show higher values of the function.ymin .
A common setting to use is ColorFunction > Hue.2.2. the color of each point represents the value at that point of the function being plotted. 2<. ColorData provides many customized sets of colors which can be used directly by ColorFunction. 2<. ColorFunction Ø HueD Out[3]= A significant resource for customized color functions is the ColorData function.2. the color ranges from black to white through intermediate shades of blue as the value of the function increases. The color function may return any Mathematica color directive. however. In[2]:= DensityPlot@Sin@xD Sin@yD. 2<.2. . . . In[3]:= DensityPlot@Sin@xD Sin@yD. . . Mesh Ø 19D Out[2]= In a density plot. 8x. 8y. 8y. The option ColorFunction allows you to specify a function which is applied to the function value to find the color at any point.68 Visualization and Graphics You can include a mesh like this. Hue or RGBColor. such as GrayLevel. In general. By default. 8x. This uses different hues to represent different values. you can specify other “color maps” for the relation between the value at a point and its color. 2<.
GrayYellowTones. NeonColors. LakeColors. TemperatureMap. IslandColors. DeepSeaColors. 2<D Out[6]= . In[6]:= ContourPlot@Sin@xD Sin@yD. SouthwestColors. SunsetColors. 8y. SiennaTones. LightTerrain. RoseColors. PigeonTones.2. ThermometerColors. StarryNightColors. FruitPunchColors. In[4]:= ColorData@"Gradients"D FuchsiaTones. BrightBands. DarkTerrain.2. SolarColors. CoffeeTones. ValentineTones. Aquamarine. AuroraColors. This DensityPlot is identical to the one above. RedBlueTones. BrassTones. . but uses the "SolarColors" gradient. . . FallColors.Visualization and Graphics 69 This shows a list of the gradients which can be accessed using ColorData. 2<. LightTemperatureMap. GreenBrownTerrain. ColorFunction Ø ColorData@"SolarColors"DD Out[5]= This gives a contour plot of the function. . GrayTones. BeachColors. DarkBands< Out[4]= 8DarkRainbow. Rainbow. Pastel. 2<. BlueGreenYellow. AlpineColors. AtlanticColors. 8y. 8x. MintColors. AvocadoColors. BrownCyanTones. CherryTones. GreenPinkTones. RedGreenSplit. CandyColors. CMYKColors. ArmyColors. PearlColors.2. WatermelonColors. PlumColors. 2<. SandyTerrain. In[5]:= DensityPlot@Sin@xD Sin@yD.2. 8x. RustTones.
.2.Full. in such a way that regions with higher z values are lighter. Contour plots produced by Mathematica are by default shaded. All or Automatic. This shows the plot with no shading. zrange< how to shade the regions. zmax <. 8y. 2<.70 Visualization and Graphics A contour plot gives you essentially a “topographic map” of a function. you can specify 8zmin . The default is to have contours corresponding to a sequence of equally spaced z values.2. The contours join points on the surface that have the same height. . or the list of z values for contours the range of values to be included. 8x. 2<. ContourShading Ø NoneD Out[7]= . option name default value ColorFunction Contours PlotRange Automatic Automatic 9Full. or a list of colors can be provided number of initial sample points in each direction the maximum number of recursive subdivi sion steps to do ContourShading Automatic PlotPoints MaxRecursion Automatic Automatic Some options for ContourPlot . or a list 8xrange.Automatic= what colors to use for shading. In[7]:= ContourPlot@Sin@xD Sin@yD. None leaves the regions blank. yrange. Hue uses a sequence of hues the total number of contours.
ThreeDimensional Graphics Primitives One of the most powerful aspects of graphics in Mathematica is the availability of threedimensional as well as twodimensional graphics primitives. you can increase the number of sample points by increasing the values of the PlotPoints and MaxRecursion options. 8x. One point to notice is that whereas a curve generated by Plot may be inaccurate if your function varies too quickly in a particular region. You can typically overcome this by increasing the value of PlotPoints or MaxRecursion. LightPurple<D Out[8]= Both DensityPlot and ContourPlot use an adaptive algorithm that subdivides parts of the plot region to obtain more sample points for a smoother representation of the function you are plotting. you can represent and render threedimensional objects in Mathematica.2. In[8]:= ContourPlot@Sin@xD Sin@yD. . ContourShading Ø 8LightRed. . Because the number of sample points is always finite. it is possible that features of your function will sometimes be missed. By combining threedimensional graphics primitives.2. 8y.Visualization and Graphics 71 This cycles the colors used for contour regions between light red and light purple. . the shape of contours generated by ContourPlot can be inaccurate if your function varies too slowly. When necessary. 2<. A rapidly varying function gives a regular pattern of contours. however. 2<. but a function that is almost flat can give irregular contours.
z1 <..8x.y1 .zmin <.ymin . In[3]:= Graphics3D@ptsD Out[3]= This gives a plot showing a line through 10 random points in three dimensions. In[1]:= rcoord := RandomReal@1.72 Visualization and Graphics Point@8x.…<D Polygon@88x1 .y2 . 810<DDD Out[4]= .z2 <. 820<D. text at position 8x.z<D Threedimensional graphics elements.8x2 . z< (see "Graphics Primitives for Text") Every time you evaluate rcoord. y.8x2 .z1 <.z<D Line@88x1 .8xmax .y. In[4]:= Graphics3D@Line@Table@rcoord.…<D point with coordinates x. it generates a random coordinate in three dimensions. y2 . z2 <. Here is a plot of the points.z2 <.ymax . y.zmax <D cuboid Text@expr. … filled polygon with the specified list of corners Cuboid@8xmin . z1 <. 8x2 .y. 83<D This generates a list of 20 random points in threedimensional space.y2 . y1 . In[2]:= pts = Table@Point@rcoordD.y1 . z line through the points 8x1 .
it generates a random triangle in threedimensional space. Thus. . all the surfaces produced by ParametricPlot3D are represented essentially as lists of polygons. you can build up any threedimensional object in Mathematica. Mathematica simply draws each element in turn. then displays them as threedimensional objects. … a multipolygon consisting of polygons poly1 . In[7]:= Graphics3D@Table@rantri. 85<DD Out[7]= By creating an appropriate list of polygons.Visualization and Graphics 73 If you give a list of graphics elements in two dimensions.line2 . a multipoint consisting of points at pt1 .…<D Primitives which can take multiple elements.pt2 . Mathematica collects together all the graphics elements you specify. with later elements obscuring earlier ones. line2 . Every time you evaluate rantri.…<D Line@8line1 .…<D Polygon@8poly1 . 83<DD This draws a single random triangle. poly2 .poly2 . In[5]:= rantri := Polygon@Table@rcoord. for example. … Point@8pt1 . In three dimensions. The triangles in front obscure those behind. however. … a multiline consisting of lines line1 . In[6]:= Graphics3D@rantriD Out[6]= This draws a collection of 5 random triangles. with the ones in front in threedimensional space obscuring those behind. pt2 .
When dealing with a very large number of primitives. this efficiently represents a very large number of triangles. some threedimensional graphics primitives have multicoordinate forms which are a more efficient representation. 83<D Using the multicoordinate form of Polygon . The interior edge joining the triangles is not outlined like the outer edges of the Polygon primitive. 1. 0. 0. The noncoplanar polygon is broken up into triangles. 0. the resulting polygons may be noncoplanar or nonconvex. Mathematica will break the polygon into triangles. 81. which are planar by definition. 0<. rantricoords defines merely the coordinates of a random triangle. In[8]:= rantricoords := Table@rcoord. 810 000<DDD Out[9]= Mathematica allows polygons in three dimensions to have any number of vertices in any configuration. before rendering it. 1<. When rendering noncoplanar polygons. In[9]:= Graphics3D@Polygon@Table@rantricoords. 0<. 80. 1<<D<D Out[10]= . Depending upon the locations of the vertices. using these multicoordinate forms where possible can both reduce the memory footprint of the resulting graphic and make it render much more quickly. 81.74 Visualization and Graphics As with the twodimensional primitives. In[10]:= Graphics3D@8Polygon@880.
z< a sphere of radius r This draws a number of random unit cubes and spheres in threedimensional space.Visualization and Graphics 75 Selfintersecting nonconvex polygons are filled according to an evenodd rule that alternates between filling and not filling at each crossing.rD Sphere@8x. z1 < and 8x2 . z + 1< a cuboid (rectangular parallelepiped) with opposite corners having the specified coordinates a cylinder of radius 1 with endpoints at 8x1 . y + 1. 810<DD Out[12]= . In[12]:= Graphics3D@Table@8Cuboid@10 rcoordD.z2 <.z1 <.z<D Sphere@8x.y. a unit cube with opposite corners having coordinates 8x.z1 <. z2 < a cylinder of radius r a unit sphere centered at 8x. 0<.y. 0. 8k. y1 .z<D Cuboid@8xmin . z< and 8x + 1. In[11]:= Graphics3D@Polygon@Table@8Cos@2 p k ê 5D.8x2 .y.rD Cuboid graphics elements.8x2 .8xmax . Sphere@10 rcoordD<.y2 .ymin . Sin@2 p k ê 5D.ymax .y2 . zmin <. 2<DDD Out[11]= Cuboid@8x.y1 . y2 .z2 <D Cylinder@8x1 .zmax <D Cylinder@8x1 .z<. y.y1 . 8. y.
you can increase the efficiency of rendering by using special options to change the number of points used by default to render Cylinder and Sphere. In[13]:= Graphics3D@Table@Cylinder@8rcoord. you can use the directives PointSize. 810 000<D. just as in two dimensions. Sphere quality can be similarly adjusted using "SpherePoints". There are however some additional directives in three dimensions. When rendering so many primitives. the number of points used to render them can be reduced with almost no perceptible change. Method Ø 8"CylinderPoints" Ø 6<D Out[13]= ThreeDimensional Graphics Directives In three dimensions. Just as in two dimensions. 83<DD. All the graphics directives for two dimensions also work in three dimensions. 820<D. . A single image can contain thousands of these primitives. rcoord<. their usage is scalable. In[1]:= pts = Table@Point@Table@RandomReal@D. Because the cylinders are so small. This generates a list of 20 random points in three dimensions. you can give various graphics directives to specify how the different elements in a graphics object should be rendered. . Note that in three dimensions. Thickness and Dashing to tell Mathematica how to render Point and Line elements. The "CylinderPoints" Method option to Graphics3D is used to reduce the rendering quality of each individual cylinder.01D.76 Visualization and Graphics Even though Cylinder and Sphere produce highquality renderings. the lengths that appear in these directives are measured as fractions of the total width of the display area for your plot.
however. 5<D. 810<. In[3]:= line = Line@Table@RandomReal@D. This shows the line dashed. Polygons are intrinsically white by default.05D. however. For Polygon objects. AbsoluteDashing@85. In[2]:= Graphics3D@8PointSize@0. Polygons continue to have an intrinsic color defined by color directives. Mathematica generates colors for polygons using a more physical approach based on simulated illumination. In two dimensions. polygons are always assumed to have an intrinsic color. with a thickness of 2 printer’s points. line<D Out[4]= For Point and Line objects. AbsoluteThickness and AbsoluteDashing if you want to measure length in absolute units.Visualization and Graphics 77 This displays the points. In three dimensions. you can use AbsolutePointSize. . they can work differently. 83<DD. pts<D Out[2]= As in two dimensions. but the final color observed when rendering the graphic may be different based upon the values of the lights shining on the polygon. the color specification directives also work the same in three dimensions as in two dimensions. with each one being a circle whose diameter is 5% of the display area width. This generates a line through 10 random points in three dimensions. specified directly by graphics directives such as RGBColor and Opacity. In[4]:= Graphics3D@8AbsoluteThickness@2D.
In[7]:= Graphics3D@8Gray. "Faces"D<. The intrinsic color value of the polygons is white. PolyhedronData@"Icosahedron". "Faces"D<D Out[6]= The intrinsic color value of the polygons becomes more obvious when using the "Neutral" lighting scheme.78 Visualization and Graphics Lighting>Automatic Lighting>None Lighting>"Neutral" use default light placements and values disable all lights light using only white light sources Some schemes for coloring polygons in three dimensions. In[5]:= Graphics3D@8PolyhedronData@"Icosahedron". Lighting Ø "Neutral"D Out[7]= . In[6]:= Graphics3D@8Gray. but defines the intrinsic color value of the polygons to be gray. PolyhedronData@"Icosahedron". "Faces"D<D Out[5]= This draws the icosahedron using the same lighting parameters. This draws an icosahedron with default lighting.
1D. 0. which is not affected by the lights. PolyhedronData@"Icosahedron". 80. Line@880. 0. The second kind are lines that were generated as the edges of polygons. .2<. .1D. Line@880. 0. In[9]:= Graphics3D@88Gray. Thickness@0. Gray.2<. Thickness@0. 80. the color directive can be scoped to the line by using a sublist. In[8]:= Graphics3D@8PolyhedronData@"Icosahedron". The first kind are lines from explicit Line primitives that you included in the graphics object. "Faces"D. "Faces"D<D Out[9]= EdgeForm@D EdgeForm@gD draw no lines at the edges of polygons use the graphics directives g to determine how to draw lines at the edges of polygons Giving graphics directives for all the edges of polygons. . 0. 2<<D<D Out[8]= As with twodimensional directives. When you render a threedimensional graphics object in Mathematica. there are two kinds of lines that can appear. 2<<D<.Visualization and Graphics 79 This applies the gray color only to the line.
and the back (inside) face fully opaque.02D<D.gbackD use gfront graphics directives for the front face of each polygon. WhiteD.5D.80 Visualization and Graphics You can tell Mathematica how to render all lines of the second kind by giving a list of graphics directives inside EdgeForm.3D<. This renders a dodecahedron with its edges shown as thick gray lines. and gback for the back Rendering the fronts and backs of polygons differently. when taken in the order that you specified them. An important aspect of polygons in three dimensions is that they have both front and back faces. In[11]:= Graphics3D@8FaceForm@8Opacity@0. Mathematica uses the following convention to define the “front face” of a polygon: if you look at a polygon from the front. PolyhedronData@"Cube". This makes the front (outside) face of each polygon mostly transparent. then the corners of the polygon will appear counterclockwise. Thickness@0. In[10]:= Graphics3D@8EdgeForm@8GrayLevel@0. PolyhedronData@"Dodecahedron". "Faces"D<D Out[11]= . "Faces"D<D Out[10]= FaceForm@gfront.
many parts of the stellated icosahedron lie outside the box. The option PlotRange specifies the range of x.5 1. This shows the stellated icosahedron. In[2]:= stel = Stellate@PolyhedronData@"Icosahedron". With the default option setting Boxed > True.Visualization and Graphics 81 Coordinate Systems for ThreeDimensional Graphics Whenever Mathematica draws a threedimensional object.5 .0 Out[4]= 0. Mathematica will include all parts. which makes Mathematica use an internal algorithm to try and include the “interesting parts” of a plot. As in two dimensions the default setting is PlotRange > Automatic. PlotRange > 8. In[4]:= Show@%. and are clipped. In[3]:= Graphics3D@stel. But in general. Axes Ø TrueD 1 0 1 1 Out[3]= 0 1 1 0 1 With this setting for PlotRange.1. y and z coordinates that Mathematica should include in the box. Mathematica in fact draws the edges of this box explicitly. This loads a package defining polyhedron operations. In[1]:= << PolyhedronOperations` This creates a stellated icosahedron. drawn in a box. 1<D 1. but drop outlying parts.0 1 0 1 1 0 1 0. "Faces"DD.0 0. it always effectively puts a cuboidal box around the object. Mathematica automatically “clips” any parts of your object that extend outside of the cuboidal box. With PlotRange > All.
In[5]:= Graphics3D@8stel. running from 0 to 1 in each dimension 8x. 0<D. sz<D are taken to run from 0 to 1 in each dimension. 0. you must then tell Mathematica how to draw the box. original coordinates scaled coordinates. specified as Scaled@8sx.zr= BoxRatios>Automatic Specifying the shape of the bounding box for threedimensional objects. the default is BoxRatios > Automatic. In three dimensions. sy. This puts a cuboid in one corner of the box. 0.z< Scaled@8sx. Scaled coordinates. This is analogous to specifying the aspect ratio of a twodimensional plot. 0.sy.2.sz<D Coordinate systems for threedimensional objects.82 Visualization and Graphics Much as in two dimensions. you can use either “original” or “scaled” coordinates to specify the positions of elements in threedimensional objects. The first step is to specify what shape the box should be.2. Cuboid@Scaled@80. For Graphics3D objects. Scaled@80. The coordinates are set up to define a righthanded coordinate system on the box. specifying that the shape of the box should be determined from the ranges of actual coordinates for its contents. . specify the ratio of side lengths for the box determine the ratio of side lengths from the range of actual coordinates (default for Graphics3D ) BoxRatios>9xr. you can use the option BoxRatios to specify the ratio of side lengths for the box.2<DD<D Out[5]= Once you have specified where various graphical elements go inside a threedimensional box.y.yr.
however. 3<. each of the special coordinates runs from 1 ê 2 to 1 ê 2 across the box.2. The lengths of the other sides of the box in this coordinate system are determined by the setting for the BoxRatios option.2. therefore. you can tell Mathematica to use any view point. 0. BoxRatios > 81. You can do this using the option ViewPoint. in which the center of the box is 80. In[6]:= Graphics3D@stel. . 0<. Some common settings for this option were given in "ThreeDimensional Surface Plots". you have to tell Mathematica from what view point you want to look at the object. . Note that the view point must always lie outside the box. View points are specified in the form ViewPoint > 8sx. sy. 5<D Out[6]= To produce an image of a threedimensional object. 8y. The special coordinates are scaled so that the longest side of the box corresponds to one unit. AxesLabel > 8"x". In general. 2<. This generates a picture using the default view point 81. 8x.Visualization and Graphics 83 This displays the stellated icosahedron in a tall box.3. In[7]:= surf = Plot3D@H2 + Sin@xDL Cos@2 yD. For a cubical box. "y". . The values si are given in a special coordinate system. 2<.3. 1.4. "z"<D Out[7]= . sz<.
ViewPoint > 85. In[8]:= Show@surf.2<D Out[8]= As you move away from the box. the perspective effect gets smaller. 1.2. 5<D Out[9]= option name default value ViewPoint ViewCenter 81. 1.2< Automatic ViewVertical 80. 5.0.84 Visualization and Graphics This is what you get with a view point close to one of the corners of the box.2.1< ViewAngle ViewVector Automatic Automatic the point in a special scaled coordinate system from which to view the object the point in the scaled coordinate system which appears at the center of the final image the direction in the scaled coordinate system which appears as vertical in the final image the opening halfangle for a simulated camera used to view the graphic the position and direction of the simulated camera in the graphic's regular coordinate system Specifying the position and orientation of threedimensional objects.4.2. In[9]:= Show@surf. ViewPoint > 81. .3.
In[10]:= Show@surf. and ViewPoint options. With many choices of view point. however. You also have to specify how you want to "frame" the object in your final image.Visualization and Graphics 85 In making a picture of a threedimensional object you have to specify more than just where you want to look at the object from. ViewCenter allows you to tell Mathematica what point in the object should appear at the center of your final image. The ViewAngle specifies. ViewVertical and ViewAngle. and facing of the camera are determined by the ViewCenter. The ViewAngle option specifies the width of the opening of the camera lens. The effective viewing angle is double the value of ViewAngle. The position. With the default setting ViewVertical > 80. You can do this by setting ViewCenter > Automatic. This means that ViewAngle can effectively be used to zoom in on a part of the image. 1 ê 2<. ViewVertical > 81. Mathematica uses the properties of a simulated camera to visualize the final image. 0<D Out[10]= . the z direction in your original coordinate system always ends up vertical in the final image. The point is specified by giving its scaled coordinates. so this setting for ViewCenter will not center the whole box in the final image area. the box will not appear symmetrical. ViewVertical specifies which way up the object should appear in your final image. 1 ê 2. With the setting ViewCenter > 81 ê 2. 0. ViewVertical. This setting for ViewVertical makes the x axis of the box appear vertical in your image. running from 0 to 1 in each direction across the box. The setting for ViewVertical gives the direction in scaled coordinates which ends up vertical in the final image. 0. The default value of ViewAngle resolves to 35°. the maximum angle from the line stretching from the ViewPoint to the ViewCenter which can be viewed by the camera. the center of the box will therefore appear at the center of your final image. 1<. in radians. orientation. which is the typical viewing angle for the human eye. You can do this using the additional options ViewCenter.
ty. ViewCenter specifies where you are looking (the center of your gaze).y. uses the values of the ViewPoint and ViewCenter options to determine the position and facing of the simulated camera position of the camera in the coordinates used for objects. .z<.tz<< Possible values of the ViewVector option. ViewVector provides the ability to position the camera using the same coordinate system used to position objects within the graphic. ViewCenter and ViewVertical. ViewPoint specifies where your head is relative to the object. settings for ViewPoint.86 Visualization and Graphics This uses ViewAngle to effectively zoom in on the center of the image. ViewCenter and ViewVertical specify how coordinates in the threedimensional box should be transformed into coordinates for your image in the final display area. you can think about it as specifying how you would look at a physical object. In terms of coordinate systems. In[11]:= Show@surf. And ViewVertical specifies which way up your head is. Instead of specifying the position and facing of the camera using scaled coordinates. but the ViewVector option offers a useful generalization. The position and facing of the camera can be fully determined by the ViewPoint and ViewCenter options. ViewAngle Ø 10 DegreeD Out[11]= When you set the options ViewPoint.z< ViewVector>88x. the facing of the camera is determined by the ViewCenter option position of the camera and of the point the camera is focused on in the coordinates used for objects ViewVector>Automatic ViewVector>8x.8tx.y.
0<. this zooms in on a particular section of the graphic.3. you can modify the final shape of your image by changing the AspectRatio option. 0. Interac . 2<<. interactive rotation can also affect the value of the ViewVertical option. drag Ctrl+drag Shift+drag rotate the graphic about its center zoom into or out of the graphic pan across the graphic in the plane of the screen Mouse gestures used for interacting with threedimensional graphics. 82. for example. then rotating the graphic causes Mathematica to change the value of the ViewPoint option. The issues however are identical to those that occur for twodimensional graphics. ViewVector Ø 8. If the position of the camera is specified using ViewVector. 0<D Out[12]= The camera is in the same position but pointing in a different direction. ViewVector Ø 88. ViewAngle Ø 20 DegreeD Out[13]= Once you have obtained a twodimensional image of a threedimensional object. 0. And you specify what region of your whole display area your image should take up by setting the PlotRegion option. In combination with ViewAngle. .5. In[12]:= Show@surf. In both cases.Visualization and Graphics 87 This specifies that the camera should be placed on the negative x axis and facing toward the center of the graphic. Thus. In[13]:= Show@surf. Mathematica makes changes to the view options.5. When interactively modifying graphics. If you have specified the position of the camera using ViewPoint. interactive rotation will instead change the value of that option. there are still some issues about how this image should be rendered.
AspectRatio > 0. 1<DD Out[15]= . You can set the option SphericalRegion > True to avoid such variation. Although in most cases this scaling is what you want. Mathematica effectively puts a sphere around the threedimensional bounding box. given the display area you specify. it does have the consequence that the size at which a particular threedimensional object is drawn may vary with the orientation of the object. Axes > False. and is drawn so that the bounding box just fits inside it. 5. With this option setting. BoxRatios > 81. This modifies the aspect ratio of the final image.3D Out[14]= Mathematica usually scales the images of threedimensional objects to be as large as possible. In[15]:= Framed@Show@surf. The sphere has its center at the center of the bounding box. and scales the final image so that the whole of this sphere fits inside the display area you specify. This draws a rather elongated version of the plot. Interactively panning the graphic changes values of the ViewCenter option.88 Visualization and Graphics tive zooming of the graphic corresponds directly to changing the ViewAngle option. In[14]:= Show@surf.
5. BoxRatios > 81. Lighting and Surface Properties With the default option setting Lighting > Automatic. which produces uniform shading all over the object. Other components are directional. 1<.Visualization and Graphics 89 With SphericalRegion > True . and produce different shading on different parts of the object. "Point lighting" simulates light emanating in all directions from one point in space. you can make the scaling of an object consistent for all orientations of the object. scale threedimensional images to be as large as possible scale images so that a sphere drawn around the threedimensional bounding box would fit in the final display area SphericalRegion>False SphericalRegion>True Changing the magnification of threedimensional images. Mathematica adds together the light from all of these sources in determining the total illumination of a particular polygon. This is useful if you create animated sequences which show a particular object in several different orientations. In[16]:= Framed@Show@surf. the final image is scaled so that a sphere placed around the bounding box would fit in the display area. "Spot lighting" is similar to point lighting. but emanates a cone of light in a particular direction. Mathematica uses a simulated lighting model to determine how to color polygons in threedimensional graphics. SphericalRegion > TrueDD Out[16]= By setting SphericalRegion > True. . One component is the "ambient lighting". Mathematica allows you to specify various components to the illumination of an object. "Directional lighting" simulates a uniform field of light pointing in the given direction.
90 Visualization and Graphics 8"Ambient". The light sources are colored respectively red. Sphere@81.pos<< 8"Spot". 0<D.color. In[2]:= Show@spheres.1. green and blue.…< Methods for specifying light sources.color.tar<. 1. 0<D<.8pos1 . Note the Lighting option takes a list of light sources.8pos. In[1]:= spheres = Graphics3D@8Sphere@8. shaded using simulated lighting using the default set of lights. Axes Ø True. 0<D. and no ambient component. AxesLabel Ø 8"x".1.a< Lighting>8light1 .1. 1. "z"<D Out[1]= This shows the result of adding ambient light. "y".1. . Blue<<D Out[2]= .pos2 << 8"Point". Lighting Ø 88"Ambient". Here is a sphere. .light2 . Sphere@81.color< 8"Directional".color. Sphere@8. uniform ambient lighting directional lighting parallel to the vector from pos1 to pos2 spherical point light source at position pos spotlight at position pos aimed at the target position tar with a halfangle opening of a a number of lights The default lighting used by Mathematica involves three point light sources. and removing all point light sources. and are placed at 45È angles on the righthand side of the object. 0<D.
PointSize@LargeD. Graphics3D@8Red. Red. 0. In[3]:= Show@8spheres. Lighting > 88"Ambient". 8"Point". 0<D<D<. Graphics3D@8Red. Red. 0. 83. 0. 0. In[4]:= Show@8spheres. so all objects in a scene will be lit evenly by light sources. 0<<<D Out[4]= . The lights are combined as appropriate. Point@83. 80. Blue<.Visualization and Graphics 91 This adds a single point light source positioned at the red point. 8"Point". Point@80. 2<D<D<. 2<<<D Out[3]= Objects do not block light sources or cast shadows. PointSize@LargeD. Lighting > 88"Ambient". Blue<.
880. 880. 80. 0. 3<. Lighting > 88"Ambient". combined with ambient lighting. 83. 15 Degree<<D Out[6]= The Lighting option controls the lighting of all objects in a scene when used as an option to Graphics3D or Show . 8y. Red. Lighting can also be used inline as a directive which specifies lighting for particular objects. In[6]:= Plot3D@Sin@x + Sin@yDD. 0. . 0<.3. The Lighting directive replaces the inherited lighting specifications. . . 0<<. Green. 0<<<<D Out[5]= This shows a spotlight positioned above the plot. 8x.92 Visualization and Graphics This adds a directional green light shining from the negative y direction. In[5]:= Show@%. RGBColor@0.6D<. 80. Lighting Ø 88"Ambient".3. 1. 0. 5<. 8"Spot". 8"Directional". 8"Point". 3<. 0. Blue<. effectively an infinite distance away. 0. 0<<. Red. .
Specularity . 8Lighting Ø 88"Point". 5<<<. and Glow to specify the way that polygons reflect or emit light. Sphere@82. Thus the polygons reflect light of any color incident on them. 0. but also on how the polygon reflects that light.Visualization and Graphics 93 The Lighting directive replaces the default value of Lighting for the two spheres after the directive. 0<D. 2. specular reflection. These directives separately specify three kinds of light emission: diffuse reflection. Using RGBColor. This is an appropriate model for materials such as uncoated white paper. 2<D<D Out[8]= The perceived color of a polygon depends not only on the light which falls on the polygon. 0<D. Green. Sphere@81. and Glow . . 5<<<. If you do not explicitly use these coloring directives. 80. Green. 80. Lighting Ø 88"Point". Specularity . 2<D<D Out[7]= This example uses list braces to restrict the effect of the Lighting directive to the middle sphere. you can specify more complicated models. 0. 1<D. Sphere@81. In[7]:= Graphics3D@8Sphere@80. 0. In[8]:= Graphics3D@8Sphere@80. 1. Mathematica effectively assumes that all polygons have matte white surfaces. You can use the graphics directives RGBColor. however. and do so equally in all directions. 1<D<. 0. 2. and glow. 1. Sphere@82.
light incident on a surface is scattered equally in all directions. the intensity of light at an angle q away from the mirror reflection direction is assumed to vary like cos HqLn . the surface is a completely diffuse reflector. Note that when a > 90È . In specular reflection. With specular exponent n. a surface reflects light in a mirrorlike way. Glow is light radiated from a surface at a certain color and intensity of light that is independent of incident light. an object may have an intrinsic specular reflection color. however. and glow directives. Most materials. you can specify intrinsic colors of the form GrayLevel@aD. As n decreases. When this kind of reflection occurs. however. Typical values of n for actual materials range from about 1 to several hundred.94 Visualization and Graphics In diffuse reflection. For materials that are effectively “white”. For each kind of light emission. where a is the angle between the incident light direction and the surface normal vector. scatter light to some extent. To get no reflection of a particular kind. and the specularly reflected light is a componentwise product of the incident light and the intrinsic specular color. When the incident light is not white. the color emitted is determined by intrinsic properties alone. when the incident light is white. you can specify light properties by giving any combination of diffuse reflection. the surface has a “shiny” or “gloss” appearance. there is no reflected light. each color component in the reflected light is a product of the corresponding component in the incident light and in the intrinsic color of the material. Mathematica allows you to specify how broad the distribution is by giving a specular exponent. and for n = 0. and some objects glow in addition to reflecting light. a surface has a "dull" or "matte" appearance. light incident at a particular angle is reflected at exactly the same angle. As n Ø ¶. Similarly. therefore. . or GrayLevel@0D. you may give the corresponding intrinsic color as Black. specular reflection. In Mathematica. For glow. with no dependence on incident light. the color of the reflected light is the material's intrinsic color. As a result. defined according to the Phong lighting model. Diffuse reflectors obey Lambert's law of light reflection. an object can have an intrinsic color. the surface becomes less “shiny”. which states that the intensity of reflected light is cosHaL times the intensity of the incident light. With a perfect mirror. For diffuse reflection. where a is the reflectance or albedo of the surface. which may be different from its diffuse reflection color. the surface behaves like a perfect mirror. Most actual materials show a mixture of diffuse and specular reflection. and so lead to reflected light that is distributed over a range of angles.
. the sphere has a “specular highlight” near the light sources. but high specular reflectance.2D. illuminated by several colored light sources.g. and is quite dark elsewhere. spec can be a number between 0 and 1 or an RGBColor specification glowing surface with color col Glow@colD Specifying surface properties of lighted objects.Visualization and Graphics 95 GrayLevel@aD RGBColor@r. Specularity@0. 5D. In[10]:= Graphics3D@8GrayLevel@0. As a result. it is important to make sure that the total intensity of light reflected from a particular polygon is never larger than 1. You will get strange effects if the intensity is larger than 1.bD Specularity @spec. This shows a sphere with the default matte white surface. In[9]:= Graphics3D@Sphere@DD Out[9]= This makes the sphere have low diffuse reflectance.8.nD matte surface with albedo a matte surface with intrinsic color surface with specularity spec and specular exponent n. Sphere@D<D Out[10]= When you set up light sources and surface colors.
False. y and z axes. "Faces"DD Out[1]= Setting Axes > True adds x. draw a cuboidal bounding box around the graphics (default) draw x. Others are different.96 Visualization and Graphics Labeling ThreeDimensional Graphics Mathematica provides various options for labeling threedimensional graphics.0 Out[2]= 0. The default for Graphics3D is to include a box. In[2]:= Show@%. Some of these options are directly analogous to those for twodimensional graphics. Axes > TrueD 1 0 1 1. discussed in "Labeling TwoDimensional Graphics".5 1. y and z axes on the edges of the box draw the z axis only draw grid lines on the faces of the box give an overall label for the plot Boxed>True Axes>True Axes>9False.0 1 0 1 0. In[1]:= Graphics3D@PolyhedronData@"Dodecahedron".5 .True= FaceGrids>All PlotLabel>text Some options for labeling threedimensional graphics.0 0. but no other forms of labeling.
and draws axes which are thicker than normal. you tell Mathematica to draw axes on the edges of the threedimensional box. AxesStyle > Thickness@0. . The option AxesEdge allows you to specify on which edge to draw each of the axes.Visualization and Graphics 97 This adds grid lines to each face of the box.ystyle. there are in principle four possible edges on which it can be drawn. In[4]:= Graphics3D@PolyhedronData@"Dodecahedron". specify the style for the box specify the style for axes specify separate styles for each axis This makes the box dashed.0 1 0 1 By setting the option Axes > True.01DD 1 0 1 1.0 0.0 0.02<D. "Faces"D. 0. BoxStyle > Dashing@80.5 1. In[3]:= Show@%.5 Out[4]= 0. FaceGrids > AllD 1 0 1 1 Out[3]= 0 1 1 0 1 BoxStyle>style AxesStyle>style AxesStyle>8xstyle.02.zstyle< Style options. Axes > True. However. for each axis.
In[5]:= Show@%. Axes > True.0 0. 1<.1 to represent larger or smaller values for the y and z coordinates. and chooses automatically where to draw the z axis.ylabel. This draws the x on the edge with larger y and z coordinates.0 When you draw the x axis on a threedimensional box.dirz < for where to draw the x axis.yspec.5 1. there are four possible edges on which the axis can be drawn.zspec= None Automatic 9diri . give no axis labels put a label on the z axis put labels on all three axes AxesLabel>None AxesLabel>zlabel AxesLabel>9xlabel. Automatic<D 1 0 1 1. .dir j = use an internal algorithm to choose where to draw all axes give separate specifications for each of the x. you can set the diri to be + 1 or .98 Visualization and Graphics AxesEdge>Automatic AxesEdge>9xspec. When you use the specification 8diry . y and z axes do not draw this axis decide automatically where to draw this axis specify on which of the four possible edges to draw this axis Specifying where to draw threedimensional axes.zlabel= Axis labels in threedimensional graphics.5 Out[5]= 0. These edges are distinguished by having larger or smaller y and z coordinates.0 0. draws no y axis. AxesEdge > 881. None.
"z"<.…= FaceGrids>99 face1 .yticks.ygrid1 ==.dirz <.…= Drawing grid lines in three dimensions. draw no tick marks place tick marks automatically tick mark specifications for each axis You can give the same kind of tick mark specifications in three dimensions as were described for twodimensional graphics in "Labeling TwoDimensional Graphics".zticks= Settings for the Ticks option. without necessarily drawing scales on them.1. ygridi to determine where and how to draw grid lines on each face FaceGrids>None FaceGrids>All FaceGrids>9 face1 . Each face is specified by a list 8dirx . By setting FaceGrids > 8 face1 . "y". "Image"D. face2 . and the third one is + 1 or . where two of the diri must be 0.Visualization and Graphics 99 You can use AxesLabel to label edges of the box. AxesLabel > 8"x". using the same kind of specifications as you give for the GridLines option in twodimensional graphics. face2 . …< you can tell Mathematica to draw grid lines only on specific faces. Ticks > NoneD y Out[6]= z x Ticks>None Ticks>Automatic Ticks>9xticks.diry . draw no grid lines on faces draw grid lines on all faces draw grid lines on the faces specified by the facei use xgridi . you can also explicitly tell Mathematica where and how to draw the grid lines. . In[6]:= Show@PolyhedronData@"Dodecahedron". For each face. 9xgrid1 . Axes > True. If you set FaceGrids > All. grid lines are drawn in gray on every face. Mathematica allows you to draw grid lines on the faces of the box that surrounds a threedimensional object.
pt2 .…<D a multipoint consisting of points at pt1 . Notebooks that use multielement forms can be less than half the size of those that do not.poly2 . FaceGrids > 880. using the multielement forms can also significantly reduce the sizes of notebook files. 1<. 0. . In[1]:= Graphics@Point@Table@RandomReal@NormalDistribution@0. … a multiline consisting of lines line1 . Here is a multipoint random distribution. … Primitives which can take multiple elements. 80. 0.line2 . In[7]:= Show@PolyhedronData@"Dodecahedron". poly2 .…<D Polygon@8poly1 .pt2 . and render up to ten times faster. Some primitives have multielement forms that can be processed and rendered more quickly by the Mathematica front end than the equivalent individual primitives. For large numbers of primitives. line2 . 1D. 2D.…<D Line@8line1 . 810 000<DDD Out[1]= .1<<D Out[7]= Efficient Representation of Many Primitives Point@8pt1 . "Image"D.100 Visualization and Graphics This draws grid lines only on the top and bottom faces of the box. … a multipolygon consisting of polygons poly1 .
dataD a graphics complex in which coordinates given as integers i in graphics primitives in data are taken to be pti Primitive for sharing coordinate data among primitives. as in meshes and graphs. In[2]:= Graphics@GraphicsComplex@880. 1<. the graph stays connected when any part of it is dragged. Primitives that share coordinates stay connected when one of them is dragged. Point@81. 8i. further efficiency can be gained by using GraphicsComplex to factor out the coordinate data. 22<EE Out[3]= . The output of Mathematica's surface. 10E.5<<.5. 8Line@881.…<.199. 80.and graphplotting functions typically use this representation. 1<. 4. 81. . In[3]:= GraphPlotATableAi Ø ModAi2 . 2. 1.05D. Here is a structure of points and lines that share coordinates. 81. 85. 8. 0<. Because the output of GraphPlot is a GraphicsComplex . 2.Visualization and Graphics 101 GraphicsComplex@ 8pt1 . GraphicsComplex is useful interactively. PointSize@. 3. Red. 5<D<DD Out[2]= In addition to being efficient. When many primitives share the same coordinate data.pt2 . 3<. 0<. 4<<D.
In[5]:= Plot3D@Sin@xD y ^ 2. numerical errors that could cause gaps between adjacent polygons are The output of Plot3D is a GraphicsComplex .102 Visualization and Graphics Any primitive may be used within a GraphicsComplex. and GraphicsComplex can be used in both 2D and 3D graphics. Point@Range@5DD >FF Out[4]= GraphicsComplex avoided. 1. is especially useful for representing meshes of polygons. 0. 8i. 8x. TextBStyleB‡ f@xD „ x. 0. 22<. 4F. 36F. 8y. Within GraphicsComplex. : Sphere@4. By using GraphicsComplex. 4<D Out[5]= . coordinate positions in primitives are replaced by indices into the coordinate data in the GraphicsComplex. This GraphicsComplex combines several types of primitives. i<. 1. 5<D. i. In[4]:= Graphics3DBGraphicsComplexBTable@8i.5D.
2 1 2 3 4 5 6 This uses StandardForm rather than TraditionalForm . 8x.8 Out[3]= 0.4 0.8 sin2 HxL Out[2]= 0.4 0. 8x. Here is a plot with default settings for all formats. 2 Pi<. 0.2 1 2 3 4 5 6 Here is the same plot. 0. 0. PlotLabel > Sin@xD ^ 2.6 0.6 0. 2 Pi<.0 0. PlotLabel > Sin@xD ^ 2.6 0.2 1 2 3 4 5 6 .4 0. FormatType > StandardFormD Sin@xD2 1. 2 Pi<.0 0.8 Out[1]= 0. but now using a 12point bold font. In[3]:= Plot@Sin@xD ^ 2. 8x. FontSize Ø 12<D 1.Visualization and Graphics 103 Formats for Text in Graphics BaseStyle>value FormatType>value Specifying formats for text in graphics. In[2]:= Plot@Sin@xD ^ 2. In[1]:= an option for the text style in a graphic an option for the text format type in a graphic Plot@Sin@xD ^ 2.0 0. PlotLabel > Sin@xD ^ 2D sin2 HxL 1. BaseStyle > 8FontWeight > "Bold".
Now all the text is in 14point Times font. the font will scale as the plot is resized.6 0. If you resize a plot whose font size is specified as a scaled quantity.0 0.4 0.2 1 2 3 4 5 6 "style" FontSize>n FontSlant>"Italic" FontWeight>"Bold" FontFamily>"name" a named style in your current stylesheet the size of font to use in printer’s points use an italic font use a bold font specify the name of the font family to use (e. "Helvetica") Typical elements used in the setting for BaseStyle. In[5]:= Plot@Sin@xD ^ 2. with one point being 1 72 inches. the text in it will not by default change size: to get text of a different size you must explicitly specify a new value for the FontSize option. In[4]:= SetOptions@Plot. If you use the standard notebook front end for Mathematica. PlotLabel > Sin@xD ^ 2D 1. Note that FontSize gives the absolute size of the font to use. "Times". . With FontSize > Scaled@sD. You can also explicitly specify how text should be formatted by using options such as FontSize and FontFamily. BaseStyle > 8FontFamily > "Times". If you resize a plot whose font size is specified as a number.8 sin2HxL Out[5]= 0. 0. the effective font size will be s scaled units in the plot.104 Visualization and Graphics This tells Mathematica what default text style to use for all subsequent plots.g. then you can set BaseStyle to be the name of a style defined in your current notebook's stylesheet. 2 Pi<. measured in units of printer’s points. 8x. FontSize Ø 14<D. "Courier".
PlotLabel > Style@Sin@xD ^ 2. In[7]:= Plot@Sin@xD ^ 2.8 0. In[6]:= Plot@Sin@xD ^ 2.optionsD StandardForm@exprD output expr in the specified style output expr using the specified font and style options output expr in StandardForm Changing the formats of individual pieces of output.6 0.05D<D 1.4 0.Visualization and Graphics 105 Now all the text resizes as the plot is resized."style"D Style@expr.0 0. 0. 2 Pi<. 8x.0 0. but modified to be in italics. This outputs the plot label using the section heading style in your current notebook. 2 Pi<. FontSlant > "Italic"DD 1.6 Out[6]= 0.8 sin2 HxL Out[7]= 0. 8x. 0.0 0.2 1 2 3 4 5 6 This uses the section heading style.4 0. In[8]:= Plot@Sin@xD ^ 2. "Section"DD 1. 0.8 sin2 HxL Out[8]= 0. "Section".6 0.4 0. 2 Pi<. BaseStyle Ø 8FontSize Ø Scaled@.2 1 2 3 4 5 6 Style@expr. PlotLabel > Style@Sin@xD ^ 2. 8x.2 1 2 3 4 5 6 .
0.0<D Twodimensional text.0<D Text@expr.or threedimensional Mathematica graphics. you can still specify formatting of text in graphics using options such as FontSize.8x.8dx. 2 Pi<. y< text positioned so that 8x. PlotLabel > Style@StandardForm@Sin@xD ^ 2D.dy<.y<.y<.81. FontSize > 12DD 1. dy< within the box that bounds the text text oriented vertically to read from bottom to top text that reads from top to bottom text that is upsidedown Text@expr. In[9]:= Plot@Sin@xD ^ 2.4 0.dy<D Text@expr.dy<.1<D Text@expr. Graphics Primitives for Text With the Text graphics primitive.0 0.8x.8dx. y< righthand end at 8x.0<D Text@expr.y<.6 0.8x.81.dy<.8x.80.80. y< centered below 8x. you can insert text at any position in two.y<.y<D Text@expr.8x.8dx.1<D Text@expr.8dx.8 Sin@xD2 Out[9]= 0.8x.1<D Text@expr.y<.81.1<D Text@expr. y< centered above 8x.8x.80.8x. y< is at relative coordinates 8dx.8x. .80.y<. 8x. Unless you explicitly specify a style or font using Style.y<.106 Visualization and Graphics This produces StandardForm output.2 1 2 3 4 5 6 You should realize that the ability to refer to styles such as "Section" depends on using the standard Mathematica notebook front end. Even if you are just using a textbased interface to Mathematica. y< text with its lefthand end at 8x. text centered at the point 8x. The complete collection of options that you can use is given in "Text and Font Options". however. the text will be given in the graphic's base style. with a 12point font.y<.
In[2]:= Show@Graphics@Text@StyleForm@"Some text". the relative coordinates that are used are taken to run from 1 to 1 in each direction across the box that bounds the text. 2<.z<D Text@expr.0 1.5 . Note that the offsets you specify need not lie in the range 1 to 1.0 1. text centered at the point 8x.5 1. Some text 2. 8n. z< text with a twodimensional offset Text@expr.8x.8sdx. 8. PlotRange > AllD x5 + 5 x4 + 10 x3 + 10 x2 + 5 x + 1 x4 + 4 x3 + 6 x2 + 4 x + 1 Out[1]= x3 + 3 x2 + 3 x + 1 x2 + 2 x + 1 x+1 Here is some vertically oriented text with its lefthand side at the point 82. 80. FontSize > 14. 2<.0 When you specify an offset for text.Visualization and Graphics 107 This generates five pieces of text.y.0 2. and displays them in a plot.0 Out[2]= 2.1. Note that you can specify the color of a piece of text by preceding the Text graphics primitive with an appropriate RGBColor or other graphics directive. 0< in this coordinate system is defined to be center of the text. 1<DD. 0<. The point 80. y. Frame > TrueD 3. 5<DD.8x.sdy<D Threedimensional text. In[1]:= Show@Graphics@Table@Text@Expand@H1 + xL ^ nD. 8n.y.5 3.z<. n<D. 82.5 2.0 1. FontWeight > "Bold"D.
80. Rectangle@80. 81.5D. 2<. In[5]:= Graphics@88GrayLevel@0. 0<. 81. Text@"Some text".108 Visualization and Graphics This puts text at the specified position in three dimensions. None 8< StandardForm background color style or font specification format type By default the text is just put straight on top of whatever graphics have already been drawn. Mathematica assumes that the text is never hidden by any polygons or other objects. Text@"a point". option name default value Background BaseStyle FormatType Options for Text . In fact. Mathematica treats sounds much like graphics. 1<D<D a point Out[3]= Note that when you use text in threedimensional graphics. 0. 2. 80. In[3]:= Graphics3D@ 8PolyhedronData@"Dodecahedron". In[4]:= Graphics@ 88GrayLevel@0.5. 81. Rectangle@80. 1<D<. "Faces"D.5<.5D. Text@"Some text".5. Background > AutomaticD<D Some text Out[5]= The Representation of Sound "Sound" describes how you can take functions and lists of data and produce sounds from them. 0. 82. 0<. 1<D<.5<D<D Some text Out[4]= Now there is a rectangle with the background color of the whole plot enclosing the text. Mathematica allows you to combine graphics with sound to create pictures with “sound tracks”. Here we discuss how sounds are represented in Mathematica. .
rD SampledSoundFunction@ f . In both cases."style"D Mathematica sound primitives. all amplitude values obtained must be between 1 and 1. In[1]:= Play@H2 + Cos@20 tDL * Sin@3000 t + 2 Sin@50 tD D. 2<D Out[1]= The Sound object contains a SampledSoundFunction primitive which uses a compiled function to generate amplitude samples for the sound. it also produces sound. In SampledSoundFunction.…<. sounds in Mathematica are represented by symbolic sound objects. and contain a list of sound primitives. On appropriate computer systems. amplitude and styling of the note. a sound with a sequence of amplitude levels.n. <<3>>. by applying the specified function to a sequence of integer arguments. In[2]:= Short@InputForm@%DD Sound@SampledSoundFunction@CompiledFunction@8_Integer<. a notelike sound is represented as a sequence of MIDI events that represent the frequency. 8<<2>><.rD SoundNote@n. sampled at rate r a sound whose amplitude levels sampled at rate r are found by applying the function f to n successive integers a notelike sound with note n.a2 . Play returns a Sound object. which represent sounds to be played in sequence. . a sound object containing a list of sound primitives Sound@8s1 . they are generated when the sound is output. or as a sequence of MIDI events. 0. duration. 16384.Visualization and Graphics 109 In analogy with graphics.t. 8t. In SoundNote. In SampledSoundList. EvaluateD. however.s2 . 8192DD Out[2]//Short= SampledSoundList@8a1 .…<D The structure of a sound object. The sound objects have head Sound. all sounds in Mathematica are represented as a sequence of amplitude samples. The functions Play and ListPlay discussed in "Sound" return Sound objects. these amplitude samples are given explicitly in a list. with the specified style At the lowest level. time specification t.
The lowlevel representation of sampled sound used by Mathematica consists of a sequence of hexadecimal numbers specifying amplitude levels.graphics. The lowlevel representation of notebased sound is as a timequantized byte stream of MIDI events.8g1 . Within Mathematica. Much as with graphics. the amplitude levels are “quantized”. you must then output it as a sound. you can specify the sample depth by replacing the sample rate argument by the list 8rate. The default is SampleDepth > 8.graphicsD Export@" file". You can use the option SampleDepth to specify how many bits should be used for each sample. .…<.graphics. amplitude levels are given as approximate real numbers between 1 and 1. export graphics to a file in a format deduced from the file name export graphics in the specified format Export@"name. and convert it to a lowerlevel form that can be handled by an external program. You can use the option SampleDepth in Play and ListPlay. In producing the lowlevel form. Play will produce a SampledSoundFunction object containing a CompiledFunction. depth<. then you can typically just copy and paste graphics and sounds directly into other programs using the standard mechanism available on your computer system. In sound primitives. which specify various parameters about the note objects." format"D export graphics to an external command Export@" file". while Play generates SampledSoundFunction primitives." format"D Export@"!command". the basic scheme is to take the Mathematica representation of the sound. Once you have generated a Sound object containing various sound primitives. With the default option setting Compiled > True. which yields 256 possible amplitude levels. If you use the notebook front end for Mathematica.…D ExportString@graphics.110 Visualization and Graphics ListPlay generates SampledSoundList primitives. such as a Mathematica front end.g2 . The quantization of time is determined automatically at playback. Exporting Graphics and Sounds Mathematica allows you to export graphics and sounds in a wide variety of formats. sufficient for most purposes.ext"." format"D export a sequence of graphics for an animation generate a string representation of exported graphics Exporting Mathematica graphics and sounds.
In[2]:= Out[2]= Export@"sinplot.tif.0 0. 8x. 0. 10<D 2.dcm.ppm) portable graymap format (.5 0. In[1]:= Plot@Sin@xD + Sin@Sqrt@2D xD. Formats in the first group are resolution independent.pgm) portable anymap format (.jpeg) PNG format (.pbm) portable pixmap format (.5 1.tiff) GIF and animated GIF (.svg) Macintosh PICT Windows metafile format (.0 1.jpg.0 1. This generates a plot. .eps".xbm) portable bitmap format (.pdf) Scalable Vector Graphics (.eps) Adobe Acrobat portable document format (. %D sinplot.wmf) TIFF (. .dic) Audio Video Interleave format (.bmp) PCX format (.png) Microsoft bitmap format (.5 2 4 6 8 10 Out[1]= This exports the plot to a file in Encapsulated PostScript format.pnm) DICOM medical imaging format (.avi) Typical graphics formats supported by Mathematica. .eps .pcx) X window system bitmap (.gif) JPEG (.Visualization and Graphics 111 "EPS" "PDF" "SVG" "PICT" "WMF" "TIFF" "GIF" "JPEG" "PNG" "BMP" "PCX" "XBM" "PBM" "PPM" "PGM" "PNM" "DICOM" "AVI" Encapsulated PostScript (.5 1.
typical resolutions are 72 dpi and above. ImageSize > x makes the width of the graphic be x printer’s points. 300 dpi and above. the lower the quality of the image you will get.aiff) Typical sound formats supported by Mathematica.wav) m law encoding (.stl) "DXF" "STL" Typical 3D geometry formats supported by Mathematica. ImageSize > 72 xi thus makes the width xi inches. you usually have to specify the absolute size at which the graphic should be rendered. for printers.aif. "WAV" "AU" "SND" "AIFF" Microsoft wave format (. Automatic Top Automatic Within Mathematica. y< scales the graphic so that it fits in an x×y region.dxf) STL stereolithography format (.snd) AIFF format (. You can do this using the ImageSize option to Export. But some require that the graphics be converted to rasters or bitmaps with a specific resolution. AutoCAD drawing interchange format (. absolute image size in printer’s points how the image is oriented in the file resolution in dpi for the image ImageSize "ImageTopOrientation" ImageResolution Options for Export. graphics are manipulated in a way that is completely independent of the resolution of the computer screen or other output device on which the graphics will eventually be rendered. The ImageResolution option for Export allows you to determine what resolution in dots per inch (dpi) should be used.au) sound file format (. . For screen display. but also the less memory the image will take to store.112 Visualization and Graphics When you export a graphic outside of Mathematica. . ImageSize > 8x. Many programs and devices accept graphics in resolutionindependent formats such as Encapsulated PostScript (EPS). The default is to produce an image that is four inches wide. The lower you set this resolution.
In[2]:= Out[2]= GraphicsGrid@88g. 8g. With Import you can read graphics and sounds in a wide variety of formats.jpg"D Out[1]= This shows an array of four copies of the image.ext"D Import@" file".Visualization and Graphics 113 Importing Graphics and Sounds Mathematica allows you not only to export graphics and sounds. Typically you will need to know the structure if you want to manipulate the data that is returned. but also to import them. . import graphics from the file name." format"D Importing graphics and sounds. and bring them into Mathematica as Mathematica expressions. g<<D Import yields expressions with different structures depending on the type of data it reads. This imports an image stored in JPEG format." format"D ImportString@"string". g<.ext in a format deduced from the file name import graphics in the specified format import graphics from a string Import@"name. In[1]:= g = Import@"ExampleDataêocelot.
optsD Graphics@Raster@dataD. Rule@<< 2 >>D. This shows the overall structure of the graphics object imported above. 200< This shows the distribution of pixel values. Here are the dimensions of the array. 1DD.graphics2 . In[6]:= ListPlot@Sort@Flatten@dDDD 220 200 Out[6]= 180 160 140 50 100 150 200 This shows a transformed version of the image.optsD 8graphics1 . In[5]:= Dimensions@dD Out[5]= 8200. In[4]:= d = g@@1. In[3]:= Shallow@InputForm@gDD Out[3]//Shallow= Graphics@Raster@<< 4 >>D. Rule@<< 2 >>DD This extracts the array of pixel values used.…< Sound@SampledSoundList@data.114 Visualization and Graphics Graphics@primitives.rDD resolutionindependent graphics resolutiondependent bitmap images animated graphics sounds Structures of expressions returned by Import. In[7]:= Out[7]= Graphics@Raster@d ^ 2 ê Max@d ^ 2DDD .
10<. Ticks Ø NoneD Out[1]= Select the curve and change its color and thickness using the Graphics Inspector. PlotRange Ø All.Visualization and Graphics 115 Editing Mathematica Graphics Introduction to Editing Mathematica Graphics An Example of Editing Graphics The following graph represents an impulse response of an ideal Low Pass Filter (LPF). .4LL. Details on each topic follow in the other parts of "Interactive Graphics". This graph illustrates some of the ways of interacting with graphics. 0.4LD ê HPi Ht . 8t. In[1]:= Plot@Sin@Pi Ht .
size. You can edit the title to change its font.116 Visualization and Graphics Using the Text tool and the TraditionalForm Text tool. color. add a plot label and axis labels. Draw vertical and horizontal lines to the maximum point with the Line tool. . and face.
Add the formula for the curve.Visualization and Graphics 117 Select the lines and make them dashed using the Graphics Inspector. Label the point with the TraditionalForm Text tool. .
For more information on each tool. New Graphic/Inset (Ctrl+1) Select/Move/Resize (o) Point (p) Line (l) Arrow (a) Disk/Circle (c) TraditionalForm Text (m) (Ctrl+g) Graphics Inspector (.118 Visualization and Graphics Drawing Tools To Open the Graphics Palette: Type Ctrl +T or choose Graphics Drawing Tools.) Get Coordinates (f) Freehand Line (s) Line Segments (g) Polygon (q) Rectangle (t) Text . click the words pointing into the palette.
m. . c. After the single use. † Click the New Graphic button on the palette. s. a. t Persistence of Tools Do one of the following: † Click a tool button to use a tool once. f. † With a graphic selected. type one of these letters: o. p.Visualization and Graphics 119 To Select a Tool: Do one of the following: † Click a tool icon on the palette. A blank drawing area with a bounding box appears. g. q. Tools New Graphic Tool Do one of the following: † Type Command +1. † Choose Graphics New Graphic. l. † Doubleclick a tool button to keep using the tool. the tool will automatically revert to the Selection tool.
You can remove or add an object to a selection with Shift+click. dragging makes it visible. You can scale the selection by dragging a handle.120 Visualization and Graphics Selection Tool You can use the Selection tool to select a graphics primitive as a whole. When an object is completely underneath another one. For more information on how to use the Selection tool. Shift+drag a handle. see "Interactive Graphics: Selecting". To scale equally in both directions. The selection is indicated by a frame with handles. Hold down the Shift key to draw the arrow horizontally or vertically. You can then drag it by dragging its highlight. Drag out a rectangle to select all the objects within it. . You can move an object by dragging it. Draw Arrow Tool Click the Draw Arrow tool and drag the pointer ( ) to draw an arrow.
Draw Line Tool Click the Draw Line tool and drag the pointer ( ) to draw a single line. . Doubleclick the Draw Freehand tool to draw multiple curves.Visualization and Graphics 121 Draw Freehand Tool Click the Draw Freehand tool button and drag the pointer ( ) to draw a curve. Hold down the Shift key to draw a horizontal or vertical line.
. You get a new segment after each click. doubleclick the last point or singleclick the first point. ) to draw a multisegment You can set the line style with the Graphics Inspector palette. Draw Line Segments Tool Click the Draw Line Segments tool and drag the pointer ( line.122 Visualization and Graphics You can set line styles with the Graphics Inspector palette. To stop.
1.0 2 3 4 5 6 .5 1 0.Visualization and Graphics 123 Draw Point Tool Click the Draw Point tool and then click to draw a point.5 1. You can set point styles with the Graphics Inspector. Place Text Tool You can place text in a graphic with the Place Text tool.0 Sine Curve 0.
0 2 3 y = SinHxL 4 5 6 Draw Rectangle Tool Click the Draw Rectangle tool and drag the pointer ( Hold down the Shift key to draw squares.5 1. .124 Visualization and Graphics Place TraditionalForm Text Tool You can place TraditionalForm text in a graphic with the Place TraditionalForm Text tool. ) to draw a rectangle. You can set face and edge styles with the Graphics Inspector palette. 1.0 0.5 1 0.
To stop. ) to draw a polygon. . ellipse.Visualization and Graphics 125 Draw Polygon Tool Click the Draw Polygon tool and drag the pointer ( You get a new segment after each click. You can set face and edge styles with the Graphics Inspector palette. Draw Circle Tool Click the Draw Circle tool and drag the pointer ( ) to draw a circle. doubleclick the last point or singleclick the first point. or disk. Hold down the Shift key to draw circles.
126 Visualization and Graphics You can draw both filled and unfilled circles. . Graphics Inspector Click the Graphics Inspector button to display the Graphics Inspector palette. depending on the currently selected fill and edge attributes. The Graphics Inspector palette lets you interactively set the style of a graphics object.
8351<. Use Command +C to copy the marked coordinates to the clipboard. Use Command +V to paste the copied coordinate values into an input cell.89. You can delete markers with Command +click.6706. .7403.792<. 0. The approximate coordinate values of the mouse position are displayed. 0. Click at other positions to add markers.Visualization and Graphics 127 Get Coordinates Tool Click the Get Coordinates tool and move the mouse pointer ( ) over a 2D graphic or a 2D plot. Click to mark the coordinates. 80.0. 1. 8. 881.7132<< Use Alt +drag to mark a rectangle and Command +C to copy the coordinates of the opposite corners.
4083<.3556<. 0.45. The frame highlight is dashed.5917<. 0.525.4111. 0.6778<. 888. 80. 0.5139<. 0. 80.3444<.4278<. 0. 0. 80. 80.4028. 1.5083<. 0. 0.3611<.3694<. 0. 80. 80. 0. 0. 0.425.3417. 80.5056<. 80.5667<.5417. 80.3917. 0. 80.4333<. 0. 80. 0.3972<.128 Visualization and Graphics Use Command +V to paste. 80.5833.6444.4528<. 80.4139. 0. 80. 0.3944. 0.5611.6861<.3861<.4722<.3722<. 80.452<<< Drag to mark a coordinate path.3972.5611.4917<.3944.0. 0. 80.4972. 0.5083<.45. 0.475<. 0. 80.4444<.4628. 0.6861.2501<. 880.5528.5194. 0.4583<. 80.1694. 0. 80. 0.4722<. 80.4861.5361.4889<.5611. 80. 80.6222<.5194. 80. 0.4194.4833. 0.6528<.3917. 0.2167.4722. 0. 0. 80.2292. Paste the coordinates into an input cell. 80. 80. 80. 0.1222.4111<.5611.4528. 80.4444<. 0. 80. 80. 80. doubleclick the background or an object in the graphic. . 80. 80.1417. then type Command +C to copy the coordinates. 0. 0. 0. 0. 80.3972<.5333<.3806<.4167<.3611<.5472.3556<.3778<.2694. 80.6889<< Selecting Graphics Objects Selecting an Object To begin editing within a graphic. 80.675. 80. 0.5139<. 0.5583. 80. 80.
When over a handle. Drag the disk or its frame highlight to move it. the arrow cursor ( . ) changes to the double arrow cursor ( .Visualization and Graphics 129 Click a disk to select it. or ). . .
130 Visualization and Graphics Drag a handle to reshape the selected disk. press Shift and drag a handle. Selecting Multiple Objects Click a disk to select it. . To resize a disk without changing its shape.
. Click outside the selected disks to deselect.Visualization and Graphics 131 Shift+click to select another disk. Drag a handle to stretch the selected disks. The two disks with crosshairs (+) at their centers are selected.
132 Visualization and Graphics Click and drag across some disks to select them. Shift+drag to deselect a group of disks. . Shift+click to deselect a selected disk.
Click to copy a rectangle. In another graphic. The rectangle will be at its original coordinates. Drag the pasted rectangle to move it out of the way.Visualization and Graphics 133 Copy and Paste The following sequence shows how to copy and paste an object from one graphic to another. doubleclick the background and paste. .
The disk disappears and a new copy of the rectangle appears once again at its original coordinates. a single click selects the target as a whole. Whether the rectangle appears above or below a disk depends on the position of the replaced disk in the internal ordering of the graphics expression.134 Visualization and Graphics Click a disk to select it. Paste the copied rectangle again. . In contrast to doubleclicking the background of the target graphic.
Doubleclick a square to select it. .Visualization and Graphics 135 Pasting now replaces the whole graphic. The three squares will be pasted. replacing the selected square. Paste the graphic copied before. Inset Objects Here is a graphic with three squares. Click the graphic and copy it.
Click the Inset to select it. . Copy the selected Inset . click the background of the graphic to deselect the Inset . To move the Inset . and paste. click anywhere inside it and drag.136 Visualization and Graphics The pasted squares are in an Inset . Move the pasted Inset to the upper right.
Click and drag an object in an Inset to move it. Objects in different Inset groups cannot be selected simultaneously. .Visualization and Graphics 137 Doubleclick an object in an Inset to select it.
Doubleclick the background and press the r key to make the Reshape tool ( ) appear. the following topics are discussed: Pointers Vertices and Circle Points Line Segments Primitives Reshaping Overlapping Objects Multiple Objects Pointers The following sequence explains how to use the Reshape tool ( . Move the pointer over a filled rectangle~the subscript on the pointer is a pair of double arrows ( ) indicating that the rectangle can be dragged. and ). .138 Visualization and Graphics Reshaping Graphics Objects In this tutorial. .
Now you can drag the vertex to reshape the line. Move the pointer over a vertex~the subscript on the pointer is a small circle ( ).Visualization and Graphics 139 You can now drag the rectangle. .
Vertices and Circle Points The following sequence shows where the selectable points of graphics primitives are located and how to select them. You can drag the line segment to reshape the line.140 Visualization and Graphics Move the pointer over a line segment~the subscript on the pointer is a small line ( ). Doubleclick the background and press the r key to make the Reshape Tool ( ) appear. . Rectangle primitives do not have selectable line segments.
Click to Shift+click another vertex to add it to the selection.Visualization and Graphics 141 Move the pointer over a vertex~the subscript on the pointer is a small circle ( select the vertex. Shift+click a selected vertex to deselect it. The other vertices are shown but are not selected. ). .
. Polygon and Line primitives have vertices at every corner. Doubleclick the background and press the r key to make the Reshape Tool ( ) appear.142 Visualization and Graphics Drag the center or the topright corner point of a Circle or Disk primitive to reshape it. The two vertices of a Rectangle primitive are at opposite corners. Line Segments The following sequence shows where the line segments of graphics primitives are located and how to select them.
Click Shift+click another line segment to add it to the selection.Visualization and Graphics 143 Move the pointer over a line segment~the subscript on the pointer is a small line ( to select the line segment. Shift+click a selected line segment to deselect it. ). .
Primitives Reshaping a Rectangle The following sequence shows how to reshape a Rectangle primitive. and Rectangle primitives do not have selectable line segments. Disk. . Polygon and Line primitives have line segments on their sides.144 Visualization and Graphics Doubleclick a line segment to select all the line segments of the polygon. Doubleclick the background and press the r key to make the Reshape Tool ( ) appear. Circle.
. Rectangle primitives do not have line segments that can be selected. Reshaping a Disk The following sequence shows how to reshape a Disk primitive.Visualization and Graphics 145 Rectangles have vertices at opposite corners. Doubleclick the background and press the r key to make the Reshape Tool ( ) appear. Click a vertex to select it. Drag the selected vertex to reshape the Rectangle.
. This keeps the topright corner point fixed in the same place but changes the shape of the disk. You can now see the topright corner point. Drag the center point.146 Visualization and Graphics Click the center point of a disk. This deselects the center point. Click the topright corner point to select it.
Visualization and Graphics 147 Drag the topright corner point to change the radius of the disk. Reshaping a Polygon The following sequence shows how to reshape the lower polygon to fit the upper polygon. The center does not change. Doubleclick the background and press the r key to make the Reshape Tool ( ) appear. . Click the vertex A.
148 Visualization and Graphics Drag the vertex A to reshape the polygon. Drag either B or C. . Click the vertex B and Shift+click the vertex C.
Visualization and Graphics 149 Click the line segment k to select it. . Click the line segment l and Shift+click the line segment m. Drag k to reshape the polygon.
. Click the line segment n and Shift+click the vertex D.150 Visualization and Graphics Drag either l or m to move them both together. Drag either n or D to move them both together.
Visualization and Graphics 151 Reshaping Lines The following sequence shows how to reshape the line below to a zigzag pattern. Doubleclick the background and press the r key to make the Reshape Tool ( ) appear. Drag A to reshape the line. . Click the vertex A.
.152 Visualization and Graphics Click the vertex B and Shift+click the vertices C and D. Drag one of the selected vertices. Click the line segment k to select it.
. Drag one of the selected line segments to move them all simultaneously. Click the line segment l and Shift+click the line segments m and n.Visualization and Graphics 153 Drag k to reshape the line.
154
Visualization and Graphics
Shift+click the vertex E to add it to the selection.
Drag one of the selected line segments or E to move them all simultaneously.
Visualization and Graphics
155
Reshaping Overlapping Objects
The following sequence shows how to reshape a hidden object.
There are four hidden rectangles underneath the disk in the middle. Doubleclick the background and press the r key to make the Reshape Tool ( ) appear.
To select one of the hidden rectangles, click the background and drag across the disk. To select the whole rectangle, you may need to start from a new position.
You can move the rectangle by dragging its highlight.
156
Visualization and Graphics
To reshape the selected hidden rectangle, first Shift+click a corner to deselect the vertex.
Then drag the other vertex.
Multiple Objects
Reshaping Multiple Rectangles
The following sequence shows how to reshape a set of rectangles simultaneously.
Doubleclick the background and press the r key to make the Reshape Tool (
) appear.
Drag one of the selected vertices. . Shift+click some vertices in the other rectangles. All of the selected rectangles will be reshaped simultaneously.Visualization and Graphics 157 Click one of the two vertices of a rectangle.
.158 Visualization and Graphics Reshaping Multiple Lines The following sequence shows how to reshape three lines simultaneously. Doubleclick the background and press the r key to make the Reshape Tool ( ) appear. Click a segment of one of the Line primitives. Shift+click segments in other Line primitives.
Click the background and drag across all the line segments and vertices around the gap in the middle. Doubleclick the background and press the r key to make the Reshape Tool ( ) appear. Reshaping with Vertices and Line Segments The following sequence shows how to reshape with different kinds of objects.Visualization and Graphics 159 Drag any one of the selected segments to simultaneously reshape the three Line primitives. .
0. Cropping.160 Visualization and Graphics Drag one of the selected line segments or vertices to simultaneously reshape the whole picture. Using the Selection tool. 8x. 3 Pi<D Shift+drag a handle to change the aspect ratio. . Resizing. click to select the graphic. Plot@Cos@xD + 1 ê 2. and Adding Margins to Graphics Changing the AspectRatio The following sequence shows how to change the aspect ratio of a plot.
Visualization and Graphics 161 Cropping The following sequence shows how to crop a portion of a plot. click a graphic to select it. Click to select the graphic.1. Plot@ChebyshevU@6. Using the Selection tool. 8x. 1<D Command +drag a handle to crop the plot. Setting Margins The following sequence shows how to set the margins of a graphic. . xD. .
0 2 4 6 .5 1. Shift+drag the frame. 1. drag a margin frame handle.5 1.0 0.162 Visualization and Graphics Drag the frame (not a handle) to push out the margins.0 0.5 6 4 2 0.0 2 4 6 To change a margin directly.5 6 4 2 0. 1. To keep the margins equal.
Disk[{4. 1/2]. . 0}]}. This input produces some disks. 0.5 6 4 2 0. 0. 0. 1. {{RGBColor[1/2.7. 2 j<D<. 4}]}}}] . 0.7. 0]. j ê 2D. . 0. 0}]}. Disk[{2. In[1]:= Graphics@Table@8RGBColor@i ê 2. Disk[{0. 8i. {RGBColor[1. 0. Shift+drag the graphics frame to the topleft corner.7.Visualization and Graphics 163 To get rid of the margins. j ê 2D. Disk[{2.0 0. {RGBColor[1/2.7. {RGBColor[1. 1].7. {RGBColor[0. 2}]}. Disk[{2. 2 j<D<. 2<DD In[3]:= êê InputForm Out[3]//InputForm= Graphics[{{{RGBColor[0. 0. 2<. 0.0 2 4 6 Graphics as Input An image is equivalent to its symbolic expression. Disk[{4.7. 4}]}}. 2<DD Out[1]= Type êê InputForm after the graphic to get the symbolic expression that corresponds to the graphic. 8j. Disk@82 i. {{RGBColor[1. 1/2]. 0]. 0. 4}]}}. 0]. You can operate on an image as you would on a symbolic expression. 8j. Disk[{0. 2<. 2}]}. 2}]}.7. {RGBColor[0. 0. Disk[{4.7. Disk[{0. 8i.7. Disk@82 i. 0. 1]. 1]. 1/2]. {RGBColor[1/2. In[2]:= Graphics@Table@8RGBColor@i ê 2.7. 0}]}. 0. 0.7.5 1.
In[4]:= ê. . Move the pointer over the 3D graphic.164 Visualization and Graphics Type a Mathematica Replace command after the output graphic and evaluate. . The pointer changes to the 3D rotate pointer Drag to rotate the graphic. Disk Ø Rectangle The disks are now replaced by squares. Out[5]= Interacting with 3D Graphics Rotate You can rotate 3D graphics with your mouse.
. Press Command and move the pointer over the 3D graphic. The pointer changes to the 3D zoom pointer Drag up to zoom in and down to zoom out. Move the pointer to a corner of the display area of the 3D graphic. Zoom In and Out with Command You can zoom in and out of 3D graphics. The pointer changes to the 3D vertical rotate pointer .Visualization and Graphics 165 Rotate about the Axis Perpendicular to the Screen You can also rotate 3D objects about the axis perpendicular to the screen with your mouse. . Click and move the pointer clockwise or counterclockwise.
. The pointer changes to the 3D pan pointer Drag to move the graphic.166 Visualization and Graphics Pan with Shift You can pan 3D graphics across the screen. Press Shift and move the pointer over the 3D graphic. .
This action might not be possible to undo. Are you sure you want to continue?