| Basic Plotting | Plotting Lists of Data |
| Options for Graphics | Parametric Plots |
| Redrawing and Combining Plots | Some Special Plots |
| Three‐Dimensional Surface Plots | Sound |
| Plot[f,{x,xmin,xmax}] | plot f as a function of x from xmin to xmax |
| Plot[{f1,f2,…},{x,xmin,xmax}] | plot several functions together |
The singularities can be omitted from the plot by using the Exclusions option:
There is a general mechanism for specifying "options" in Wolfram Language functions. Each option has a definite name. As the last arguments to a function like Plot, you can include a sequence of rules of the form name->value, to specify the values for various options. Any option for which you do not give an explicit rule is taken to have its "default" value.
| Plot[f,{x,xmin,xmax},option->value] |
make a plot, specifying a particular value for an option
|
A function like Plot has many options that you can set. Usually you will need to use at most a few of them at a time. If you want to optimize a particular plot, you will probably do best to experiment, trying a sequence of different settings for various options.
option name | default value | |
| AspectRatio | 1/GoldenRatio | |
| Axes | True | whether to include axes |
| AxesLabel | None | labels to be put on the axes; ylabel specifies a label for the axis, {xlabel,ylabel} for both axes |
| AxesOrigin | Automatic | the point at which axes cross |
| BaseStyle | {} | the default style to use for the plot |
| FormatType | TraditionalForm | the default format type to use for text in the plot |
| Frame | False | whether to draw a frame around the plot |
| FrameLabel | None | labels to be put around the frame; give a list in clockwise order starting with the lower axis |
| FrameTicks | Automatic | what tick marks to draw if there is a frame; None gives no tick marks |
| GridLines | None | what grid lines to include; Automatic includes a grid line for every major tick mark |
| PlotLabel | None | an expression to be printed as a label for the plot |
| PlotRange | Automatic | the range of coordinates to include in the plot; All includes all points |
| Ticks | Automatic | what tick marks to draw if there are axes; None gives no tick marks |
Setting the AspectRatio option changes the whole shape of your plot. AspectRatio gives the ratio of height to width. Its default value is the inverse of the Golden Ratio—supposedly the most pleasing shape for a rectangle:
| Automatic | use internal algorithms |
| None | do not include this |
| All | include everything |
| True | do this |
| False | do not do this |
| Automatic |
show at least a large fraction of the points, including the "interesting" region (the default setting)
|
| All | show all points |
| {ymin,ymax} | show a specific range of values |
| {xrange,yrange} | show the specified ranges of and values |
It is important to realize that since the Wolfram Language can only sample your function at a limited number of points, it can always miss features of the function. The Wolfram Language adaptively samples the functions, increasing the number of samples near interesting features, but it is still possible to miss something. By increasing PlotPoints, you can make the Wolfram Language sample your function at a larger number of points. Of course, the larger you set PlotPoints to be, the longer it will take the Wolfram Language to plot any function, even a smooth one.
option name | default value | |
| PlotStyle | Automatic |
a list of lists of graphics primitives to use for each curve (see
"Graphics Directives and Options"
)
|
| ClippingStyle | None | what to draw when curves are clipped |
| Filling | None | filling to insert under each curve |
| FillingStyle | Automatic | style to use for filling |
| PlotPoints | 50 | the initial number of points at which to sample the function |
| MaxRecursion | Automatic | the maximum number of recursive subdivisions allowed |
This uses PlotStyle to specify a dashed curve:
When plotting multiple functions, PlotStyle settings in a list are used sequentially for each function:
When a PlotStyle contains a sublist, the settings are combined:
By default nothing is indicated when the PlotRange is set, so that it cuts off curves:
Setting ClippingStyle to a list defines the style for the parts cut off at the bottom and top:
| Show[plot,option->value] | redraw a plot with options changed |
| Show[plot1,plot2,…] | combine several plots |
| GraphicsGrid[{{plot1,plot2,…},…}] | draw an array of plots |
| InputForm[plot] | show the underlying textual description of the plot |
By using Show with a sequence of different options, you can look at the same plot in many different ways. You may want to do this, for example, if you are trying to find the best possible setting of options.
You can also use Show to combine plots. All of the options for the resulting graphic will be based upon the options of the first graphic in the Show expression.
All Wolfram Language graphics are expressions and can be manipulated in the same way as any other expression. Doing these kinds of manipulations does not require the use of Show.
This replaces all instances of the symbol Line with the symbol Point in the graphics expression represented by gj0:
Using Show[plot1,plot2,…] you can combine several plots into one. GraphicsGrid allows you to draw several plots in an array.
| GraphicsGrid[{{plot11,plot12,…},…}] | draw a rectangular array of plots |
| GraphicsRow[{plot1,plot2,…}] | draw several plots side by side |
| GraphicsColumn[{plot1,plot2,…}] | draw a column of plots |
| GraphicsGrid[plots,Spacings->{h,v}] | put the specified horizontal and vertical spacing between the plots |
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:
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->{h,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.
When you make a plot, the Wolfram Language 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 the Wolfram Language 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. (the Wolfram Language always plots the actual points it has; it avoids using smoothed or splined curves, which can give misleading results in mathematical graphics.)
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:
| Plot3D[f,{x,xmin,xmax},{y,ymin,ymax}] | |
make a three‐dimensional plot of f as a function of the variables x and y | |
Three-dimensional graphics can be rotated in place by dragging the mouse inside the graphic. Dragging inside the graphic causes the graphic to tumble in a direction that follows the mouse, and dragging around the borders of the graphic causes the graphic to spin in the plane of the screen. Dragging the graphic while holding down the Shift key causes the graphic to pan. Use the Ctrl key to zoom.
There are many options for three‐dimensional plots in the Wolfram System. Some are discussed here; others are described in "The Structure of Graphics and Sound".
The first set of options for three‐dimensional plots is largely analogous to those provided in the two‐dimensional case.
option name | default value | |
| Axes | True | whether to include axes |
| AxesLabel | None | labels to be put on the axes: zlabel specifies a label for the axis, {xlabel,ylabel,zlabel} for all axes |
| BaseStyle | {} | the default style to use for the plot |
| Boxed | True | whether to draw a three-dimensional box around the surface |
| FaceGrids | None | how to draw grids on faces of the bounding box; All draws a grid on every face |
| LabelStyle | {} | style specification for labels |
| Lighting | Automatic | simulated light sources to use |
| Mesh | Automatic | whether an mesh should be drawn on the surface |
| PlotRange | {Full,Full,Automatic} | the range of or other values to include |
| SphericalRegion | False | whether to make the circumscribing sphere fit in the final display area |
| ViewAngle | All | angle of the field of view |
| ViewCenter | {1,1,1}/2 | point to display at the center |
| ViewPoint | {1.3,-2.4,2} | the point in space from which to look at the surface |
| ViewVector | Automatic | position and direction of a simulated camera |
| ViewVertical | {0,0,1} | direction to make vertical |
| BoundaryStyle | Automatic | how to draw boundary lines for surfaces |
| ClippingStyle | Automatic | how to draw clipped parts of surfaces |
| ColorFunction | Automatic | how to determine the color of the surfaces |
| Filling | None | filling under each surface |
| FillingStyle | Opacity[.5] | style to use for filling |
| PlotPoints | 25 | the number of points in each direction at which to sample the function; specifies different numbers in the and directions |
| PlotStyle | Automatic | graphics directives for the style of each surface |
This redraws the previous plot with options changed. With this setting for PlotRange, only the part of the surface in the range is shown:
Probably the single most important issue in plotting a three‐dimensional surface is specifying where you want to look at the surface from. The ViewPoint option for Plot3D and Show allows you to specify the point in space from which you view a surface. The details of how the coordinates for this point are defined are discussed in "Coordinate Systems for Three-Dimensional Graphics". When rotating a graphic using the mouse, you are adjusting the ViewPoint value.
Here is a surface, viewed from the default view point {1.3,-2.4,2}. This view point is chosen to be "generic", so that visually confusing coincidental alignments between different parts of your object are unlikely:
The ViewPoint option also accepts various symbolic values that represent common view points:
| {1.3,-2.4,2} | default view point |
| Front | in front, along the negative direction |
| Back | in back, along the positive direction |
| Above | above, along the positive direction |
| Below | below, along the negative direction |
| Left | left, along the negative direction |
| Right | right, along the positive direction |
To add an extra element of realism to three‐dimensional graphics, the Wolfram System by default colors three‐dimensional surfaces using a simulated lighting model. In the default case, the Wolfram System assumes that there are four point light sources plus ambient lighting shining on the object. "Lighting and Surface Properties" describes how you can set up other light sources, and how you can specify the reflection properties of an object.
Lighting can also be specified using a string that represents a collection of lighting properties. For example, the option setting Lighting->"Neutral" uses a set of white lights, and so can be faithfully reproduced on a black and white output device such as a printer.
The ColorFunction option by default uses Lighting->"Neutral" so that the surface colors are not distorted by colored lights:
| ListPlot[{y1,y2,…}] | plot y1,y2,… at x values 1,2,… |
| ListPlot[{{x1,y1},{x2,y2},…}] | plot points (x1,y1),… |
| ListLinePlot[list] | join the points with lines |
| ListPlot3D[{{z11,z12,…},{z21,z22,…},…}] | |
make a three‐dimensional plot of the array of heights zyx | |
| ListPlot3D[{{x1,y1,z1},{x2,y2,z2},…}] | |
make a three-dimensional plot with heights zi at positions {xi,yi} | |
| ListContourPlot[array] | make a contour plot |
| ListDensityPlot[array] | make a density plot |
| ParametricPlot[{fx,fy},{t,tmin,tmax}] | |
make a parametric plot | |
| ParametricPlot[{{fx,fy},{gx,gy},…},{t,tmin,tmax}] | |
plot several parametric curves together | |
| ParametricPlot3D[{fx,fy,fz},{t,tmin,tmax}] | |
make a parametric plot of a three‐dimensional curve | |
| ParametricPlot3D[{fx,fy,fz},{t,tmin,tmax},{u,umin,umax}] | |
make a parametric plot of a three‐dimensional surface | |
| ParametricPlot3D[{{fx,fy,fz},{gx,gy,gz},…},…] | |
plot several objects together | |
ParametricPlot3D[{fx,fy,fz},{t,tmin,tmax}] is the direct analog in three dimensions of ParametricPlot[{fx,fy},{t,tmin,tmax}] in two dimensions. In both cases, the Wolfram Language effectively generates a sequence of points by varying the parameter t, then forms a curve by joining these points. With ParametricPlot, the curve is in two dimensions; with ParametricPlot3D, it is in three dimensions.
ParametricPlot3D[{fx,fy,fz},{t,tmin,tmax},{u,umin,umax}] creates a surface, rather than a curve. The surface is formed from a collection of quadrilaterals. 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.
This shows the same surface as before, but with the coordinates distorted by a quadratic transformation:
This produces a torus. Varying u yields a circle, while varying t rotates the circle around the axis to form the torus:
You should realize that when you draw surfaces with ParametricPlot3D, the exact choice of parametrization is often crucial. You should be careful, for example, to avoid parametrizations in which all or part of your surface is covered more than once. Such multiple coverings often lead to discontinuities in the mesh drawn on the surface, and may make ParametricPlot3D take much longer to render the surface.
| LogPlot[f,{x,xmin,xmax}] | generate a linear-log plot |
| LogLinearPlot[f,{x,xmin,xmax}] | generate a log-linear plot |
| LogLogPlot[f,{x,xmin,xmax}] | generate a log-log plot |
| ListLogPlot[list] | generate a linear-log plot from a list of data |
| ListLogLinearPlot[list] | generate a log-linear plot from a list of data |
| ListLogLogPlot[list] | generate a log-log plot from a list of data |
| DateListPlot[list] | generate a plot from a list of data with date coordinates |
| DateListLogPlot[list] | generate a linear-log plot from a list of data with date coordinates |
| PolarPlot[r,{t,tmin,tmax}] | generate a polar plot of the radius r as a function of angle t |
| SphericalPlot3D[r,{theta,min,max},{phi,min,max}] | |
generate a three-dimensional spherical plot | |
| RevolutionPlot3D[f,{t,tmin,tmax}] | generate a three-dimensional surface of revolution |
| BarChart[list] | plot a list of data as a bar chart |
| PieChart[list] | plot a list of data as a pie chart |
| ErrorListPlot[{{x1,y1,dy1},…}] | generate a plot with error bars |
| BoxWhiskerPlot[list] | generate a box-and-whisker plot of data |
| ParetoPlot[list] | generate a Pareto plot of data |
| PairwiseScatterPlot[data] | plot pairs of coordinates for multivariate data |
Sound Playback
For example, just as you can use Plot[f,{x,xmin,xmax}] to plot a function, so also you can use Play[f,{t,0,tmax}] to “play” 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.
| Play[f,{t,0,tmax}] | play a sound with amplitude f as a function of time t in seconds |
Sounds produced by Play can have any waveform. They do not, for example, have to consist of a collection of harmonic pieces. In general, the amplitude function you give to Play specifies the instantaneous signal associated with the sound. This signal is typically converted to a voltage, and ultimately to a displacement. Note that amplitude is sometimes defined to be the peak signal associated with a sound; in the Wolfram System, it is always the instantaneous signal as a function of time.
Play is set up so that the time variable that appears in it is always measured in absolute seconds. When a sound is actually played, its amplitude is sampled a certain number of times every second. You can specify the sample rate by setting the option SampleRate.
| Play[f,{t,0,tmax},SampleRate->r] | play a sound, sampling it r times a second |
In general, the higher the sample rate, the better high‐frequency components in the sound will be rendered. A sample rate of r typically allows frequencies up to hertz. The human auditory system can typically perceive sounds in the frequency range 20 to 22000 hertz (depending somewhat on age and sex). The fundamental frequencies for the 88 notes on a piano range from 27.5 to 4186 hertz.
You can use Play[{f1,f2,…}] to produce stereo sound. In general, the Wolfram System supports any number of sound channels.
| ListPlay[{a1,a2,…},SampleRate->r] | play a sound with a sequence of amplitude levels |
The function ListPlay allows you simply to give a list of values which are taken to be sound amplitudes sampled at a certain rate.
When sounds are actually rendered by the Wolfram System, only a certain range of amplitudes is allowed. The option PlayRange in Play and ListPlay specifies how the amplitudes you give should be scaled to fit in the allowed range. The settings for this option are analogous to those for the PlotRange graphics option discussed in "Options for Graphics".
| PlayRange->Automatic | use an internal procedure to scale amplitudes |
| PlayRange->All | scale so that all amplitudes fit in the allowed range |
| PlayRange->{amin,amax} | make amplitudes between amin and amax fit in the allowed range, and clip others |
While it is often convenient to use the setting PlayRange->Automatic, you should realize that Play may run significantly faster if you give an explicit PlayRange specification, so it does not have to derive one.
| EmitSound[snd] | emit a sound when evaluated |
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. Sounds can be played without the need for user intervention or producing output by using EmitSound. In fact, the internal implementation of Sound buttons uses EmitSound when the button is pressed.