# Graphics Directives and Options

When you set up a graphics object in

*Mathematica*, 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.

Out[1]= | |

Only the rectangle in the first sublist is affected by the

GrayLevel directive.

Out[2]= | |

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 *Mathematica* color specifications.

*Mathematica* 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.

Out[3]= | |

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 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.

*Mathematica* 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.

*Mathematica* 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.

Out[4]= | |

This makes each point have a diameter equal to one-tenth of the width of the plot.

Out[5]= | |

Here each point has size 3 in absolute units.

Out[6]= | |

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[{w_{1},w_{2},...}] | show all lines as a sequence of dashed segments, with lengths , , ... |

AbsoluteDashing[{w_{1},w_{2},...}] | 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.

Out[7]= | |

Here is a picture of the lines.

Out[8]= | |

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 equal-length segments.

Out[9]= | |

This gives a dot-dashed line.

Out[10]= | |

Dashing can be turned off by specifying an empty list. Here,

Dashing is turned off for only the second line.

Out[11]= | |

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.

Out[12]= | |

This specifies that the entire multipoint should use large, green points.

Out[13]= | |

The

CapForm directive lets you specify the shapes of the end caps of lines. End cap shapes can be

,

, or

.

This shows the different shapes available to

CapForm.

Out[14]= | |

CapForm specifies that lines end exactly at their endpoints.

end caps extend one-half line width beyond the ends of a line.

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.

Out[15]= | |

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.

Out[16]= | |

Specifying an explicit larger miter limit gives a pointed star.

Out[17]= | |

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.

Out[18]= | |

One way to use

*Mathematica* 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->style | specify a style to be used for all curves in Plot |

PlotStyle->{{style_{1}},{style_{2}},...} | specify styles to be used (cyclically) for a sequence of curves in Plot |

MeshStyle->style | specify a style to be used for a mesh in density and surface graphics |

BoxStyle->style | specify a style to be used for the bounding box in three-dimensional graphics |

Some graphics options for specifying styles.

This generates a plot in which all curves are specified to use the same style.

Out[19]= | |

A different

PlotStyle expression can be used to give specific styles to each curve.

Out[20]= | |

The various "style options" allow you to specify how particular graphical elements in a plot should be rendered.

*Mathematica* also provides options that affect the rendering of the whole plot.

Background->color | specify the background color for a plot |

BaseStyle->color | specify the base style for a plot, affecting elements not affected by PlotStyle |

Prolog->g | give graphics to render before a plot is started |

Epilog->g | give graphics to render after a plot is finished |

Graphics options that affect whole plots.

This draws the plot in white on a gray background.

Out[21]= | |

This makes the axes white as well.

Out[22]= | |