# The Structure of Graphics

"Graphics and Sound" discusses how to use functions like Plot and ListPlot to plot graphs of functions and data. This tutorial discusses how *Mathematica* represents such graphics, and how you can program *Mathematica* to create more complicated images.

The basic idea is that *Mathematica* represents all graphics in terms of a collection of *graphics primitives*. The primitives are objects like Point, Line, and Polygon, which represent elements of a graphical image, as well as directives such as RGBColor and Thickness.

In[1]:= |

Out[1]= |

*Mathematica*represents the graphics. Each point is represented as a coordinate in a Point graphics primitive. All the various graphics options used in this case are also given.

In[2]:= |

Out[2]//InputForm= | |

Each complete piece of graphics in *Mathematica* is represented as a *graphics object*. There are several different kinds of graphics object, corresponding to different types of graphics. Each kind of graphics object has a definite head that identifies its type.

Graphics[list] | general two-dimensional graphics |

Graphics3D[list] | general three-dimensional graphics |

Graphics objects in *Mathematica*.

The functions like Plot and ListPlot discussed in "The Structure of Graphics and Sound" all work by building up *Mathematica* graphics objects and then displaying them.

You can create other kinds of graphical images in *Mathematica* by building up your own graphics objects. Since graphics objects in *Mathematica* are just symbolic expressions, you can use all the standard *Mathematica* functions to manipulate them.

Graphics objects are automatically formatted by the *Mathematica* front end as graphics upon output. Graphics may also be printed as a side effect using the Print command.

In[3]:= |

Out[3]= |

Show[g,opts] | display a graphics object with new options specified by opts |

Show[g_{1},g_{2},...] | display several graphics objects combined using the options from |

Show[g_{1},g_{2},...,opts] | display several graphics objects with new options specified by opts |

Show can be used to change the options of an existing graphic or to combine multiple graphics.

In[5]:= |

Out[5]= |

In[6]:= |

Out[6]= |

In[7]:= |

Out[7]= |

Graphics directives | Examples: RGBColor, Thickness |

Graphics options | Examples: PlotRange, Ticks, AspectRatio, ViewPoint |

Local and global ways to modify graphics.

Given a particular list of graphics primitives, *Mathematica* provides two basic mechanisms for modifying the final form of graphics you get. First, you can insert into the list of graphics primitives certain *graphics directives*, such as RGBColor, which modify the subsequent graphical elements in the list. In this way, you can specify how a particular set of graphical elements should be rendered.

In[8]:= |

Out[8]= |

In[9]:= |

Out[9]//InputForm= | |

In[10]:= |

Out[10]= |

By inserting graphics directives, you can specify how particular graphical elements should be rendered. Often, however, you want to make global modifications to the way a whole graphics object is rendered. You can do this using *graphics options*.

In[11]:= |

Out[11]= |

In[12]:= |

Out[12]//InputForm= | |

You can specify graphics options in Show. As a result, it is straightforward to take a single graphics object and show it with many different choices of graphics options.

Notice however that Show always returns the graphics objects it has displayed. If you specify graphics options in Show, then these options are automatically inserted into the graphics objects that Show returns. As a result, if you call Show again on the same objects, the same graphics options will be used, unless you explicitly specify other ones. Note that in all cases new options you specify will overwrite ones already there.

Options[g] | give a list of all graphics options for a graphics object |

Options[g,opt] | give the setting for a particular option |

Finding the options for a graphics object.

Some graphics options can be used as options to visualization functions that generate graphics. Options which can take the right-hand side of Automatic are sometimes resolved into specific values by the visualization functions.

In[13]:= |

Out[13]= |

*Mathematica*uses an internal algorithm to compute an explicit value for PlotRange in the resulting graphic.

In[14]:= |

Out[14]= |

FullGraphics[g] | translate objects specified by graphics options into lists of explicit graphics primitives |

Finding the complete form of a piece of graphics.

When you use a graphics option such as Axes, the *Mathematica* front end automatically draws objects such as axes that you have requested. The objects are represented merely by the option values rather than by a specific list of graphics primitives. Sometimes, however, you may find it useful to represent these objects as the equivalent list of graphics primitives. The function FullGraphics gives the complete list of graphics primitives needed to generate a particular plot, without any options being used.

In[15]:= |

Out[15]= |

In[16]:= |

Out[16]//Short= | |