Plotting and Visualization
Prerequisites: Numerics and linear algebra
Graphics are expressions like any other, so you can store, combine, and transform them. This lesson describes each plot rather than showing it.
More kinds of plots
Plot3D[Sin[x] Cos[y], {x, -3, 3}, {y, -3, 3}]
ContourPlot[x^2 + y^2, {x, -2, 2}, {y, -2, 2}, Contours -> 5]
ParametricPlot[{Cos[t], Sin[2 t]}, {t, 0, 2 Pi}]
PolarPlot[1 + Cos[t], {t, 0, 2 Pi}]
DensityPlot[Sin[x y], {x, 0, 3}, {y, 0, 3}]
Plot3Ddraws a surface you can rotate with the mouse.ContourPlotshows level curves — here five circles. It also plots equations:ContourPlot[x^2 + y^2 == 1, ...]draws a circle.ParametricPlotandPolarPlotdraw curves given by formulas int.
Styling
Plot[{Sin[x], Cos[x]}, {x, 0, 2 Pi},
PlotStyle -> {Blue, {Red, Dashed}},
PlotRange -> {-1.5, 1.5},
Frame -> True,
FrameLabel -> {"x", "value"},
PlotTheme -> "Scientific"]
Every plotting function takes options; look them up on the function's
documentation page. PlotTheme sets many at once.
Combining graphics
p1 = Plot[x^2, {x, -2, 2}];
p2 = ListPlot[{{-1, 1}, {0, 0}, {1, 1}}, PlotStyle -> Red];
Show[p1, p2]
GraphicsGrid[{{p1, p2}}]
Showoverlays graphics on the same axes.GraphicsGrid,GraphicsRow, andGraphicsColumnplace them side by side.
Drawing with primitives
Graphics[{Blue, Disk[{0, 0}, 1], Red, Rectangle[{1, 1}, {2, 2}],
Black, Line[{{-1, -1}, {2, 2}}], Text["origin", {0, -1.2}]}]
A graphic is a list of primitives (Point, Line, Circle, Disk,
Rectangle, Polygon, Text) and directives (colors, Thick,
Dashed, Opacity) that apply to what follows.
Interactivity and animation
Manipulate[
Plot[a Sin[b x + c], {x, 0, 2 Pi}, PlotRange -> {-3, 3}],
{a, 1, 3}, {b, 1, 5, 1}, {{c, 0, "phase"}, 0, 2 Pi}]
Three sliders: {b, 1, 5, 1} moves in steps of 1, and {{c, 0, "phase"}, 0, 2 Pi} sets an initial value and a label. Animate works
the same way but plays automatically. ListAnimate turns a list of
frames into an animation.
Exporting
Export["surface.png", Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}], ImageResolution -> 200]
Export["wave.gif", Table[Plot[Sin[x + t], {x, 0, 2 Pi}], {t, 0, 2 Pi, Pi/8}]]
surface.png
wave.gif
A list of graphics exported to GIF becomes an animation. Vector formats (PDF, SVG) are best for papers and slides.