Graphics Directives and Options

When you set up a graphics object in the Wolfram Language, you typically give a list of graphical elements. You can include in that list graphics directives which specify how subsequent elements in the list should be rendered.

In general, the graphical elements in a particular graphics object can be given in a collection of nested lists. When you insert graphics directives in this kind of structure, the rule is that a particular graphics directive affects all subsequent elements of the list it is in, together with all elements of sublists that may occur. The graphics directive does not, however, have any effect outside the list it is in.

The first sublist contains the graphics directive GrayLevel:
Click for copyable input
Only the rectangle in the first sublist is affected by the GrayLevel directive:
Click for copyable input
GrayLevel[i]gray level between 0 (black) and 1 (white)
RGBColor[r,g,b]color with specified red, green and blue components, each between 0 and 1
Hue[h]color with hue h between 0 and 1
Hue[h,s,b]color with specified hue, saturation and brightness, each between 0 and 1

Basic Wolfram Language color specifications.

The Wolfram Language accepts the names of many colors directly as color specifications. These color names, such as Red, Gray, LightGreen, and Purple, are implemented as variables which evaluate to an RGBColor specification. The color names can be used interchangeably with color directives.

The first plot is colored with a color name, while the second one has a fine-tuned RGBColor specification:
Click for copyable input

The function Hue[h] provides a convenient way to specify a range of colors using just one parameter. As h varies from 0 to 1, Hue[h] runs through red, yellow, green, cyan, blue, magenta, and back to red again. Hue[h,s,b] allows you to specify not only the "hue", but also the "saturation" and "brightness" of a color. Taking the saturation to be equal to one gives the deepest colors; decreasing the saturation toward zero leads to progressively more "washed out" colors.

When you give a graphics directive such as RGBColor, it affects all subsequent graphical elements that appear in a particular list. The Wolfram Language also supports various graphics directives which affect only specific types of graphical elements.

The graphics directive PointSize[d] specifies that all Point elements which appear in a graphics object should be drawn as circles with diameter d. In PointSize, the diameter d is measured as a fraction of the width of your whole plot.

The Wolfram Language also provides the graphics directive AbsolutePointSize[d], which allows you to specify the "absolute" diameter of points, measured in fixed units. The units are of an inch, approximately printer's points.

PointSize[d]give all points a diameter d as a fraction of the width of the whole plot
AbsolutePointSize[d]give all points a diameter d measured in absolute units

Graphics directives for points.

Here is a list of points:
Click for copyable input
This makes each point have a diameter equal to onetenth of the width of the plot:
Click for copyable input
Here each point has size 3 in absolute units:
Click for copyable input
Thickness[w]give all lines a thickness w as a fraction of the width of the whole plot
AbsoluteThickness[w]give all lines a thickness w measured in absolute units
Dashing[{w1,w2,}]show all lines as a sequence of dashed segments, with lengths w1, w2,
AbsoluteDashing[{w1,w2,}]use absolute units to measure dashed segments
CapForm[type]give all lines endcaps of the specified type
JoinForm[type]give all lines joins of the specified type

Graphics directives for lines.

This generates a list of lines with different absolute thicknesses:
Click for copyable input
Here is a picture of the lines:
Click for copyable input

The Dashing graphics directive allows you to create lines with various kinds of dashing. The basic idea is to break lines into segments which are alternately drawn and omitted. By changing the lengths of the segments, you can get different line styles. Dashing allows you to specify a sequence of segment lengths. This sequence is repeated as many times as necessary in drawing the whole line.

This gives a dashed line with a succession of equallength segments:
Click for copyable input
This gives a dotdashed line:
Click for copyable input
Dashing can be turned off by specifying an empty list. Here, Dashing is turned off for only the second line:
Click for copyable input

Graphics directives which require a numerical size specification can also accept values of Tiny, Small, Medium, and Large. For each directive, these values have been fine-tuned to produce an appearance which will seem appropriate to the human eye.

This specifies a large thickness with medium dashing:
Click for copyable input
This specifies that the entire multipoint should use large, green points:
Click for copyable input

The CapForm directive lets you specify the shapes of the end caps of lines. End cap shapes can be "Butt", "Square", or "Round".

This shows the different shapes available to CapForm:
Click for copyable input

CapForm["Butt"] specifies that lines end exactly at their endpoints. "Square" end caps extend one-half line width beyond the ends of a line. "Round" end caps are half-circles whose diameter is the width of the line.

You can also specify the shapes of the joins between line segments via the JoinForm directive.

Here are the shapes available to JoinForm:
Click for copyable input
JoinForm[{"Miter",d}]extend the join by at most d times the line width

Specifying the maximum length of miter joins.

When the angle between adjacent line segments is small, the point at a miter join can be very long. Excessively long points are by default truncated to bevel joins. The length at which this happens, the "miter limit", is by default set so that the points of 5-pointed stars are sharp, but more acute joins are beveled. You can specify an explicit miter limit using JoinForm to control exactly when sharp joins are beveled. The miter limit is the number of line widths that the point at a join is allowed to extend past the vertex of the join before it is beveled.

The points on this 7-pointed star are blunted by the default miter limit:
Click for copyable input
Specifying an explicit larger miter limit gives a pointed star:
Click for copyable input
RoundingRadius->rspecify that corners should be rounded with radius r

The RoundingRadius option to Rectangle.

The corners of Rectangle primitives can be rounded with the RoundingRadius option, which specifies the radius of the rectangle's corners. The actual rounding is limited to the half-length of an adjacent side.

Here are rectangles with various amounts of corner rounding:
Click for copyable input

One way to use Wolfram Language graphics directives is to insert them directly into the lists of graphics primitives used by graphics objects. Sometimes, however, you want the graphics directives to be applied more globally, and for example to determine the overall "style" with which a particular type of graphical element should be rendered. There are typically graphics options which can be set to specify such styles in terms of lists of graphics directives.

PlotStyle->stylespecify a style to be used for all curves in Plot
PlotStyle->{{style1},{style2},}specify styles to be used (cyclically) for a sequence of curves in Plot
MeshStyle->stylespecify a style to be used for a mesh in density and surface graphics
BoxStyle->stylespecify a style to be used for the bounding box in threedimensional graphics

Some graphics options for specifying styles.

This generates a plot in which all curves are specified to use the same style:
Click for copyable input
A different PlotStyle expression can be used to give specific styles to each curve:
Click for copyable input

The various "style options" allow you to specify how particular graphical elements in a plot should be rendered. The Wolfram Language also provides options that affect the rendering of the whole plot.

Background->colorspecify the background color for a plot
BaseStyle->colorspecify the base style for a plot, affecting elements not affected by PlotStyle
Prolog->ggive graphics to render before a plot is started
Epilog->ggive graphics to render after a plot is finished

Graphics options that affect whole plots.

This draws the plot in white on a gray background:
Click for copyable input
This makes the axes white as well:
Click for copyable input