# Coordinate Systems for Two-Dimensional Graphics

When you set up a graphics object in *Mathematica*, you give coordinates for the various graphical elements that appear. When *Mathematica* renders the graphics object, it has to translate the original coordinates you gave into "display coordinates" that specify where each element should be placed in the final display area.

PlotRange->{{x_{min},x_{max}},{y_{min},y_{max}}} | the range of original coordinates to include in the plot |

Option that determines translation from original to display coordinates.

When *Mathematica* renders a graphics object, one of the first things it has to do is to work out what range of original and coordinates it should actually display. Any graphical elements that are outside this range will be clipped, and not shown.

The option PlotRange specifies the range of original coordinates to include. As discussed in "Options for Graphics", the default setting is PlotRange->Automatic, which makes *Mathematica* try to choose a range which includes all "interesting" parts of a plot, while dropping "outliers". By setting PlotRange->All, you can tell *Mathematica* to include everything. You can also give explicit ranges of coordinates to include.

In[1]:= |

In[2]:= |

Out[2]= |

In[3]:= |

Out[3]= |

AspectRatio->r | make the ratio of height to width for the display area equal to r |

AspectRatio->Automatic | determine the shape of the display area from the original coordinate system |

Specifying the shape of the display area.

What we have discussed so far is how *Mathematica* translates the original coordinates you specify into positions in the final display area. What remains to discuss, however, is what the final display area is like.

On most computer systems, there is a certain fixed region of screen or paper into which the *Mathematica* display area must fit. How it fits into this region is determined by its "shape" or aspect ratio. In general, the option AspectRatio specifies the ratio of height to width for the final display area.

It is important to note that the setting of AspectRatio does not affect the meaning of the scaled or display coordinates. These coordinates always run from 0 to 1 across the display area. What AspectRatio does is to change the shape of this display area.

For two-dimensional graphics, AspectRatio is set by default to Automatic. This determines the aspect ratio from the original coordinate system used in the plot instead of setting it at a fixed value. One unit in the direction in the original coordinate system corresponds to the same distance in the final display as one unit in the direction. In this way, objects that you define in the original coordinate system are displayed with their "natural shape".

In[4]:= |

Out[4]= |

In[5]:= |

Out[5]= |

Sometimes, you may find it convenient to specify the display coordinates for a graphical element directly. You can do this by using scaled coordinates Scaled[{sx, sy}] rather than . The scaled coordinates are defined to run from 0 to 1 in and , with the origin taken to be at the lower-left corner of the plot range.

{x,y} | original coordinates |

Scaled[{sx,sy}] | coordinates scaled to the plot range |

ImageScaled[{sx,sy}] | coordinates scaled to the display area |

Coordinate systems for two-dimensional graphics.

In[6]:= |

Out[6]= |

In[7]:= |

Out[7]= |

In[8]:= |

Out[8]= |

When you use , Scaled[{sx, sy}], or ImageScaled[{sx, sy}], you are specifying the position either completely in original coordinates, or completely in scaled coordinates. Sometimes, however, you may need to use a combination of these coordinate systems. For example, if you want to draw a line at a particular point whose length is a definite fraction of the width of the plot, you will have to use original coordinates to specify the basic position of the line, and scaled coordinates to specify its length.

You can use Scaled[{dsx, dsy}, {x, y}] to specify a position using a mixture of original and scaled coordinates. In this case, gives a position in original coordinates, and gives the offset from the position in scaled coordinates.

Circle[{x,y},Scaled[sx]] | a circle whose radius is scaled to the width of the plot range |

Disk[{x,y},Scaled[sx]] | a disk whose radius is scaled to the width of the plot range |

FontSize->Scaled[sx] | specification for a font size scaled to the width of the plot range |

Some places where Scaled can be used with a single argument.

In[9]:= |

Out[9]= |

Scaled[{sdx,sdy},{x,y}] | scaled offset from original coordinates |

ImageScaled[{sdx,sdy},{x,y}] | image scaled offset from original coordinates |

Offset[{adx,ady},{x,y}] | absolute offset from original coordinates |

Offset[{adx,ady},Scaled[{sx,sy}]] | absolute offset from scaled coordinates |

Offset[{adx,ady},ImageScaled[{sx,sy}]] | absolute offset from image scaled coordinates |

Positions specified as offsets.

In[10]:= |

Out[10]= |

In[11]:= |

Out[11]= |

In most kinds of graphics, you typically want the relative positions of different objects to adjust automatically when you change the coordinates or the overall size of your plot. But sometimes you may instead want the offset from one object to another to be constrained to remain fixed. This can be the case, for example, when you are making a collection of plots in which you want certain features to remain consistent, even though the different plots have different forms.

Offset[{adx, ady}, position] allows you to specify the position of an object by giving an absolute offset from a position that is specified in original or scaled coordinates. The units for the offset are printer's points, equal to of an inch.

When you give text in a plot, the size of the font that is used is also specified in printer's points. Therefore, a 10-point font, for example, has letters whose basic height is 10 printer's points. You can use Offset to move text around in a plot, and to create plotting symbols or icons which match the size of the text.

Using scaled coordinates, you can specify the sizes of graphical elements as fractions of the size of the display area. You cannot, however, tell *Mathematica* the actual physical size at which a particular graphical element should be rendered. Of course, this size ultimately depends on the details of your graphics output device, and cannot be determined for certain within *Mathematica*. Nevertheless, graphics directives such as AbsoluteThickness discussed in "Graphics Directives and Options" do allow you to indicate "absolute sizes" to use for particular graphical elements. The sizes you request in this way will be respected by most, but not all, output devices. (For example, if you optically project an image, it is neither possible nor desirable to maintain the same absolute size for a graphical element within it.)