Introduction to Graphics and Sound

Tom Wickham-Jones

Wolfram Research

Graphical Commands

Function Plotting

Plot[ Sin[ x], {x,0,2Pi}]

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

Plot3D[ Sin[x y],{x,0,2Pi}, {y,0,Pi}]

ContourPlot[ Exp[ -Sqrt[ x^2 + y^2]] Cos[ ArcTan[x,y]],
						{x,-1,1},{y,-1,1}]

DensityPlot[ Tan[x y], {x,-Pi,Pi}, {y,-Pi, Pi}]

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

Play[ Sin[ 2Pi 400 t], {t,0,1}]

ListPlotting

Table[ x^3, {x,8}]

ListPlot[%]

The Result of a Plot

Plot[x,{x,0,4}]

InputForm[%]

Adaptive and Non-Adaptive Plotting

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

GraphicsArray

Table[ Plot[ Sin[ i x + j], {x,0,2Pi}, 
	DisplayFunction -> Identity],
	{i,4}, {j,0,Pi, Pi/2}]

Show[ GraphicsArray[%]]

Graphical Components

Primitives, Directives and Options

Graphics[ {Line[{{0,0}, {1,1}}],
          Polygon[{{.1,0}, {1,0}, {1,.9}}]}]

Show[ %]

Show[ Graphics[ {AbsoluteThickness[ 10], 
                 Line[{{ 0,0}, {1,1}}]}]]

Scope of Directives

p = Show[ Graphics[ {
		GrayLevel[ 0],
			{ RGBColor[1,0,0],
		  	  Line[{{0,0}, {1,1}}],
		  	  {	Line[{{0,1},{1,2}}]}},
		Polygon[{{0,2}, {0,3}, {1,3},{1,2}}]}]]

Options

Options[ Graphics]

Show[ p, Axes -> True]

FullOptions

Plot[ Tan[x], {x,0,2Pi}]

FullOptions[%, PlotRange]

Rectangle

f[x_] := Exp[ -x/10] - Cos[30 x] Exp[ -3 x]

short = Plot[ f[x], {x,0,1}, Frame -> True]

Plot[ f[x], {x,0,50},
		Frame -> True,
		Prolog -> Rectangle[{18, .5}, {48, 1.2}, short]]

Raster and RasterArray

rast = RasterArray[ Table[ Hue[ h, s, 1],
		{h,0,1,.01}, {s,0,1,.01}]] ;

Show[ Graphics[ rast]]

Absolute Sizes

AbsoluteThickness, AbsoluteDashing and AbsolutePointSize

Show[ Graphics[ {AbsolutePointSize[ 36],
				 Point[{0,0}]}]]

SurfaceGraphics ContourGraphics DensityGraphics

Plot3D[ x y, {x,0,1}, {y,0,1}, PlotPoints -> 2]

InputForm[%]

GraphicsArray

Sound

Text and Fonts

$DefaultFont

Plot[ Sin[x], {x,0,4}, DefaultFont -> 
                       {"Helvetica", 10}]

Axes, Grids and Labels

Axes

Plot[ Sin[x], {x,0,2Pi}]

Plot[ Sin[x], {x,0,2Pi}, AxesOrigin -> {Pi, -.5}]

Plot[ Sin[x], {x,0,2Pi}, Frame -> True]

Show[%, FrameLabel ->
	{"Number 1", "Number 2", "Number 3", "Number 4"}]

GridLines

Plot[ Exp[-x] - Exp[-2 x], {x,0,4},
			 GridLines -> Automatic,
			 Frame -> True]

Three-Dimensional

<<Graphics`Polyhedra`

Show[ Graphics3D[ Dodecahedron[]]]

Show[%, Boxed -> False]

Show[%, Axes -> True]

Show[%, Boxed -> True, FaceGrids -> All]

Sound

Play[ Sin[ 2Pi 400 t], {t,0,1}]

Show[%]

InputForm[%]

mysound = First[%]

Plot[ Sin[x], {x,0,2Pi}, Prolog -> mysound]

Graphics Packages

Load the package: use Mathematica filename.

<<Graphics`Graphics`

LogPlot[ Exp[x] + x^4, {x,1,5}]

PostScript and HardCopy Output

$DisplayFunction

$Display

line = Graphics[ Line[{{0,0}, {1,1}}]]

Display[ "tmp.ps", %]

!!tmp.ps

Printing