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.
This generates a plot of a list of points.
shows how 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.
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.
object is computed by Mathematica
, but its output is suppressed by the semicolon.
A side effect output can be generated using the Print
command. It has no Out
label because it is a side effect.
|Show[g,opts]||display a graphics object with new options specified by opts|
|Show[g1,g2,...]||display several graphics objects combined using the options from |
|Show[g1,g2,...,opts]||display several graphics objects with new options specified by opts|
Displaying graphics objects.
Show can be used to change the options of an existing graphic or to combine multiple graphics.
This uses Show
to adjust the Background
option of an existing graphic.
This uses Show
to combine two graphics. The values used for PlotRange
and other options are based upon those which were set for the first graphic.
Here, new options are specified for the entire graphic.
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.
This creates a two-dimensional graphics object that contains the Polygon
shows the complete graphics object.
This takes the graphics primitive created above and adds the graphics directives RGBColor
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.
By adding the graphics option Frame
you can modify the overall appearance of the graphics.
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.
uses an internal algorithm to compute an explicit value for PlotRange
in the resulting graphic.
|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.
This plots a list of values.
yields a graphics object that includes graphics primitives representing axes and so on.