Options for Graphics

When the Wolfram Language plots a graph for you, it has to make many choices. It has to work out what the scales should be, where the function should be sampled, how the axes should be drawn, and so on. Most of the time, the Wolfram Language will probably make pretty good choices. However, if you want to get the very best possible pictures for your particular purposes, you may have to help the Wolfram Language in making some of its choices.

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 (RefLink[Plot, paclet:ref/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.

Choosing an option for a plot.

A function like (RefLink[Plot, paclet:ref/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.

Each time you produce a plot, you can specify options for it. "Redrawing and Combining Plots" will also discuss how you can change some of the options, even after you have produced the plot.

Some of the options for (RefLink[Plot, paclet:ref/Plot]). These can also be used in (RefLink[Show, paclet:ref/Show]).

Here is a plot with all options having their default values:

Plot[Sin[x^2],{x,0,3}]

This draws axes on a frame around the plot:

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

This specifies labels for the x and y axes. The expressions you give as labels are printed just as they would be if they appeared as (RefLink[TraditionalForm, paclet:ref/TraditionalForm]) Wolfram Language output. You can give any piece of text by putting it inside a pair of double quotes:

Plot[Sin[x^2],{x,0,3},AxesLabel->{"x value",Sin[x^2]}]

You can give several options at the same time, in any order:

Plot[Sin[x^2],{x,0,3},Frame->True,GridLines->Automatic]

Setting the (RefLink[AspectRatio, paclet:ref/AspectRatio]) option changes the whole shape of your plot. (RefLink[AspectRatio, paclet:ref/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:

Plot[Sin[x^2],{x,0,3},AspectRatio->1]

Some common settings for various options.

When the Wolfram Language makes a plot, it tries to set the x and y scales to include only the "interesting" parts of the plot. If your function increases very rapidly, or has singularities, the parts where it gets too large will be cut off. By specifying the option (RefLink[PlotRange, paclet:ref/PlotRange]), you can control exactly what ranges of x and y coordinates are included in your plot.

Settings for the option (RefLink[PlotRange, paclet:ref/PlotRange]).

The setting for the option (RefLink[PlotRange, paclet:ref/PlotRange]) gives explicit y limits for the graph. With the y limits specified here, the bottom of the curve is cut off:

Plot[Sin[x^2],{x,0,3},PlotRange->{0,1.2}]

The Wolfram Language always tries to plot functions as smooth curves. As a result, in places where your function wiggles a lot, the Wolfram Language will use more points. In general, the Wolfram Language tries to adapt its sampling of your function to the form of the function. There is a limit, however, which you can set, to how finely the Wolfram Language will ever sample a function.

The function sin((1/x)) wiggles infinitely often when x≃0. the Wolfram Language tries to sample more points in the region where the function wiggles a lot, but it can never sample the infinite number that you would need to reproduce the function exactly. As a result, there are slight glitches in the plot:

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

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 (RefLink[PlotPoints, paclet:ref/PlotPoints]), you can make the Wolfram Language sample your function at a larger number of points. Of course, the larger you set (RefLink[PlotPoints, paclet:ref/PlotPoints]) to be, the longer it will take the Wolfram Language to plot any function, even a smooth one.

More options for (RefLink[Plot, paclet:ref/Plot]). These cannot be used in (RefLink[Show, paclet:ref/Show]).

This uses (RefLink[PlotStyle, paclet:ref/PlotStyle]) to specify a dashed curve:

Plot[Sin[x^2],{x,0,3},PlotStyle->Dashed]

When plotting multiple functions, (RefLink[PlotStyle, paclet:ref/PlotStyle]) settings in a list are used sequentially for each function:

Plot[{Sin[x^2], Cos[x^2]},{x,0,3},PlotStyle->{Red,Blue}]

When a (RefLink[PlotStyle, paclet:ref/PlotStyle]) contains a sublist, the settings are combined:

Plot[{Sin[x^2], Cos[x^2]},{x,0,3},PlotStyle->{Red,{Blue,Thick}}]

By default nothing is indicated when the (RefLink[PlotRange, paclet:ref/PlotRange]) is set, so that it cuts off curves:

Plot[{Sin[x^2], Cos[x^2]},{x,0,3},PlotRange->0.9]

Setting (RefLink[ClippingStyle, paclet:ref/ClippingStyle]) to (RefLink[Automatic, paclet:ref/Automatic]) draws a dashed line where a curve is cut off:

Plot[{Sin[x^2], Cos[x^2]},{x,0,3},PlotRange->0.9,ClippingStyle->Automatic]

Setting (RefLink[ClippingStyle, paclet:ref/ClippingStyle]) to a list defines the style for the parts cut off at the bottom and top:

Plot[{Sin[x^2], Cos[x^2]},{x,0,3},PlotRange->0.9,ClippingStyle->{Green,Red}]

This specifies filling between the curve and the x axis:

Plot[Sin[x^2],{x,0,3},Filling->Axis]

The filling can be specified to extend to an arbitrary height, such as the bottom of the graphic. Filling colors are automatically blended where they overlap:

Plot[{Sin[x],Cos[x]},{x,0,3},Filling->Bottom]

This specifies a specific filling to be used only for the first curve:

Plot[{Sin[x],Cos[x]},{x,0,3},Filling->{1->.5}]

This shows a filling from the first curve to the second using a nondefault filling style:

Plot[{Sin[x],Cos[x]},{x,0,3},Filling->{1->{2}},FillingStyle->LightBrown]