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

In[1]:= |

Out[1]= |

In[2]:= |

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.

In[3]:= |

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

In[4]:= |

Out[4]= |

In[5]:= |

Out[5]= |

In[6]:= |

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.

In[7]:= |

Out[7]= |

In[8]:= |

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.

In[9]:= |

Out[9]= |

In[10]:= |

Out[10]= |

In[11]:= |

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.

In[12]:= |

Out[12]= |

In[13]:= |

Out[13]= |

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

In[14]:= |

Out[14]= |

CapForm["Butt"] 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.

In[15]:= |

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.

In[16]:= |

Out[16]= |

In[17]:= |

Out[17]= |

RoundingRadius->r | specify 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.

In[18]:= |

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.

In[19]:= |

Out[19]= |

In[20]:= |

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.

In[21]:= |

Out[21]= |

In[22]:= |

Out[22]= |