[proxy] reference.wolfram.com← back | site home | direct (HTTPS) ↗ | proxy home | ◑ dark◐ light

Graphics and Sound—Wolfram Documentation

Basic PlottingPlotting Lists of Data
Options for GraphicsParametric Plots
Redrawing and Combining PlotsSome Special Plots
ThreeDimensional Surface PlotsSound
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
AspectRatio1/GoldenRatio
the heighttowidth ratio for the plot; Automatic sets it from the absolute and coordinates
AxesTrue
whether to include axes
AxesLabelNone
labels to be put on the axes; ylabel specifies a label for the axis, {xlabel,ylabel} for both axes
AxesOriginAutomatic
the point at which axes cross
BaseStyle{}
the default style to use for the plot
FormatTypeTraditionalForm
the default format type to use for text in the plot
FrameFalse
whether to draw a frame around the plot
FrameLabelNone
labels to be put around the frame; give a list in clockwise order starting with the lower axis
FrameTicksAutomatic
what tick marks to draw if there is a frame; None gives no tick marks
GridLinesNone
what grid lines to include; Automatic includes a grid line for every major tick mark
PlotLabelNone
an expression to be printed as a label for the plot
PlotRangeAutomatic
the range of coordinates to include in the plot; All includes all points
TicksAutomatic
what tick marks to draw if there are axes; None gives no tick marks
Some of the options for Plot. These can also be used in Show.
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 Ratiosupposedly 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
PlotStyleAutomatic
a list of lists of graphics primitives to use for each curve (see "Graphics Directives and Options" )
ClippingStyleNone
what to draw when curves are clipped
FillingNone
filling to insert under each curve
FillingStyleAutomatic
style to use for filling
PlotPoints50
the initial number of points at which to sample the function
MaxRecursionAutomatic
the maximum number of recursive subdivisions allowed
More options for Plot. These cannot be used in Show.
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:
This specifies filling between the curve and the axis:
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
When you redraw the plot, you can change some of the options. This changes the choice of scale:
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.
This uses PlotRange to override the explicit value set for gj0:
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:
ThreeDimensional Surface Plots
Plot3D[f,{x,xmin,xmax},{y,ymin,ymax}]
make a threedimensional plot of f as a function of the variables x and y
This makes a threedimensional plot of the function :
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 threedimensional 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 threedimensional plots is largely analogous to those provided in the twodimensional case.
option name
default value
AxesTrue
whether to include axes
AxesLabelNone
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
BoxedTrue
whether to draw a three-dimensional box around the surface
FaceGridsNone
how to draw grids on faces of the bounding box; All draws a grid on every face
LabelStyle{}
style specification for labels
LightingAutomatic
simulated light sources to use
MeshAutomatic
whether an mesh should be drawn on the surface
PlotRange{Full,Full,Automatic}
the range of or other values to include
SphericalRegionFalse
whether to make the circumscribing sphere fit in the final display area
ViewAngleAll
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
ViewVectorAutomatic
position and direction of a simulated camera
ViewVertical{0,0,1}
direction to make vertical
BoundaryStyleAutomatic
how to draw boundary lines for surfaces
ClippingStyleAutomatic
how to draw clipped parts of surfaces
ColorFunctionAutomatic
how to determine the color of the surfaces
FillingNone
filling under each surface
FillingStyleOpacity[.5]
style to use for filling
PlotPoints25
the number of points in each direction at which to sample the function; specifies different numbers in the and directions
PlotStyleAutomatic
graphics directives for the style of each surface
Some options for Plot3D. The first set can also be used in Show.
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 threedimensional 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 threedimensional graphics, the Wolfram System by default colors threedimensional 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 threedimensional 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
This gives a list of pairs:
This makes a threedimensional plot of the array of values:
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 threedimensional curve
ParametricPlot3D[{fx,fy,fz},{t,tmin,tmax},{u,umin,umax}]
make a parametric plot of a threedimensional surface
ParametricPlot3D[{{fx,fy,fz},{gx,gy,gz},},]
plot several objects together
Threedimensional parametric plots.
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 highfrequency 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.
The internal structure of Sound objects is discussed in "The Representation of Sound".