Professional Documents
Culture Documents
graphics2.nb
Mathematica Graphics
Dennis Silverman
Mathematical Physics 212 B
Department of Physics and Astronomy
U . C . Irvine
Simple Plotting
In[11]:= Plot@Tan@xD, 8x, -Pi, Pi<, AxesLabel -> 8"x", "Tan@xD"<D
Tan@xD
40
20
x
-3
-2
-1
-20
-40
Out[11]= Graphics
? Plot
Plot@f, 8x, xmin, xmax<D generates a plot of f as a function of x from xmin to
xmax. Plot@8f1, f2, ... <, 8x, xmin, xmax<D plots several functions fi.
? ListPlot
ListPlot@8y1, y2, ... <D plots a list of values. The x coordinates for each point
are taken to be 1, 2, ... . ListPlot@88x1, y1<, 8x2, y2<, ... <D plots a list of
values with specified x and y coordinates.
ListPlots are also provided with most other types of fancier plots .
graphics2.nb
3
2
1
-3 -2 -1
-1
1 2 3 4
-2
-3
Graphics
In[1]:= << GraphicsGraphics
Out[9]= Graphics
graphics2.nb
0.6
0.4
0.2
2
10
-0.2
Graphics
For a numerical solution, an interpolating function is set up automatically,
and then the function is evaluated in the plot routine by using Evaluate,
without resolving the equation for each plot point .
In[20]:= NDSolve@8y@xD == 3 y@xD, y@0D == 1<, y, 8x, 0, 1<D
Out[20]= 88y InterpolatingFunction@880., 1.<<, <>D<<
In[21]:= Plot@Evaluate@y@xD . %D, 8x, 0, 1<D
20
15
10
5
0.2
0.4
0.6
0.8
Out[21]= Graphics
Operations on Graphs
By clicking on a graph with the left mouse button or with graphics commands,
you can move, resize, Rotate3D, etc . the graphics .
graphics2.nb
Graphics Output
Mathematica generates Postscript graphics,
and they can also be output as encapsulated postscript to fit as figures in a larger page .
Print graphics with : PSPrint@graphics objectsD .
Save graphics with : Display@"file", graphicsD .
Graphics Options
?? Plot
Plot@f, 8x, xmin, xmax<D generates a plot of f as a function of x from xmin to
xmax. Plot@8f1, f2, ... <, 8x, xmin, xmax<D plots several functions fi.
Attributes@PlotD = 8HoldAll, Protected<
Options@PlotD = 8AspectRatio -> GoldenRatio^ H-1L, Axes -> Automatic, AxesLabel -> None,
AxesOrigin -> Automatic, AxesStyle -> Automatic, Background -> Automatic,
ColorOutput -> Automatic, Compiled -> True, DefaultColor -> Automatic,
Epilog -> 8<, Frame -> False, FrameLabel -> None, FrameStyle -> Automatic,
FrameTicks -> Automatic, GridLines -> None, ImageSize -> Automatic,
MaxBend -> 10., PlotDivision -> 30., PlotLabel -> None, PlotPoints -> 25,
PlotRange -> Automatic, PlotRegion -> Automatic, PlotStyle -> Automatic,
Prolog -> 8<, RotateLabel -> True, Ticks -> Automatic, DefaultFont :> $DefaultFont,
DisplayFunction :> $DisplayFunction, FormatType :> $FormatType, TextStyle :> $TextStyle<
We note here :
PlotPoints -> 100, default is 15
PlotRange -> 880, 1<, 8-2, 2<<, default is Automatic
Gridlines -> Automatic, default is none .
PlotLabel -> "Title", can be used .
AxesLabel -> ylabel, like "Time", or both labels in 8xlabel, ylabel<
Frame -> True, adds a frame, the default being False .
Options@functionD lists all options for any function in Mathematica
Options@PlotD
SetOptions@function, option -> value, ...D resets the defaults .
graphics2.nb
3
2
1
0
-1
-2
-3
-3
-2
-1
ContourGraphics
Density Plotting
DensityPlot@Sin@xD Sin@yD, 8x, -Pi, Pi<, 8y, -Pi, Pi<, PlotPoints -> 100D
3
2
1
0
-1
-2
-3
-3 -2 -1
DensityGraphics
graphics2.nb
3D Plots
g3d := Plot3D@Sin@x yD, 8x, 0, Pi<, 8y, 0, Pi<D
g3d
1
0.5
0
-0.5
-1
0
3
2
1
1
2
3 0
SurfaceGraphics
This can be modified with the options :
ViewPoint -> 8x, y, z< point to view from, and
PlotPoints -> 8nx, ny< .
Plot3D@Sin@x yD, 8x, -Pi, Pi<, 8y, -Pi, Pi<, ViewPoint -> 80, 0, 2<,
PlotPoints -> 860, 60<D
1
00.5
-0.5
-1
2
-2
-2
SurfaceGraphics
graphics2.nb
? ListPlot3D
ListPlot3D@arrayD generates a three-dimensional plot of a surface representing
an array of height values. ListPlot3D@array, shadesD generates a plot with each
element of the surface shaded according to the specification in shades.
Parametric Plots
ParametricPlot3D@8Sin@D Cos@D, Sin@D Sin@D, Cos@D<, 8, 0, Pi 2<,
8, -Pi 2, Pi 2<D
1
0.5
0
-0.5
-1
1
0.75
0.5
0.25
0
0
0.25
0.5
0.75
Graphics3D
graphics2.nb
PlotVectorField3D@8x, y, z<, 8x, -1, 1<, 8y, -1, 1<, 8z, -1, 1<D
Graphics3D
In[25]:= PlotGradientField3D@1 Sqrt@x ^ 2 + y ^ 2 + z ^ 2D, 8x, 0.3, 1<, 8y, 0.3, 1<, 8z, 0.3, 1<D
Adding Text
Besides the AxesLabel and PlotLabel options, direct text can be added by the Text command,
where expr in the following has double quotes "text" around the text .
Text@expr, 8x, y<D has text centered at 8x, y< . It can also be placed with
Text@expr, 8x, y<, 8-1, 0<D left hand end at x, y;
80, -1< centered above x, y;
80, 1< centered below x, y, and etc .
Animation
In[1]:= << GraphicsAnimation