Guide to TickControl

A guide to the TickControl package, and notes on creating plots suitable for publication.

Elizabeth A. Praton 
Franklin & Marshall College, Dept. of Physics & Astronomy 
July 2004; revised August 2005

TickControl

The functions provided in this package allow you to easily control the spacing, size, and labeling of ticks on plot frames or axes.  Rather than having to specify the position, label, and size of each tick individually, these functions allow you to characterize the desired set or sets of major and minor ticks in one step.   The resulting ticklist(s) will automatically span the entire plot region.

Note:  To make this package accessible, yet keep it separate from the standard packages, create a folder called "Graphics" inside Mathematica's "AddOns" —> "ExtraPackages" folder.  Put the TickControl package into this new Graphics folder.

Functions for generating lists of specifications for major or minor ticks

Options for MajorTickList

This loads the package.

<< Graphics`TickControl`

This gives a list of tick specifications for ticks from 0 to 10 in steps of 5, size 0.02.  Each tick specification has the form {x, label, {plen, nlen}}, where x is the tick position, label is the tick label, and plen is the length in the positive direction.  Note that the length in the negative direction is always zero.

MajorTickTable[{0, 10}, {5, 0.02}]

This reverses the sign of the tick labels.

MajorTickTable[{0, 10}, {5, 0.02}, ReverseAxis -> True]

This gives a list of tick specifications for minor ticks from 0 to 5 in steps of 1.  Minor ticks are always unlabeled.

MinorTickTable[{0, 5}, {1, 0.01}]

This leaves off the first label in a list of major tick specifications.  (This is useful in cases where you want a tick but the label interferes/overlaps with something else.)

MajorTickTable[{0, 10}, {5, 0.02}, 
      NoFirstLabel -> True]

Function for generating single list of major and minor ticks

Options for TickTable

Here is a list of list of tick specifications from 0 to 10, with major ticks every 5 units and minor ticks every 1 unit;  the sign of the tick labels are reversed, and the size of the major ticks is larger than the default.

TickTable[{0, 10}, {5, 1}, ReverseAxis -> True, 
      MajorSize -> 0.05]

Here is a list of tick specifications from 0 to 2π, with major ticks spaced π units apart and minor ticks space π/2 units apart.

TickTable[{0, 2 Pi}, {Pi,  Pi/2}]

Here is a plot of a sine function, with x-axis major ticks every π units and y-axis major ticks every 1 unit.

Plot[
        Sin[x], {x, 0, 
          4  Pi}, 
Ticks -> {TickTable[{0, 
                4  Pi}, {Pi, Pi/2}], 
            TickTable[{-1, 1}, {1, 0.5}]}];

Here is a plot with axes tick labels automatically generated by TickTable2D.

Plot[Sin[x], {x, 0, 4  Pi},  
        Ticks -> TickTable2D[{Pi, Pi/2}, {1, 0.5}]];

Here is a 3D plot with axes tick labels generated by TickTable3D.

Plot3D[Sin[x*y], {x, 0, 3  Pi}, {y, 0, 1}, Shading -> False, 
        Ticks -> 
          TickTable3D[{Pi, Pi/2}, {0.2, 0.1}, {1, 0.5} ]];

Function for generating four lists of major and minor tick specifictions (for four sides of frame)

Option for FrameTickTable

Here is a framed plot of a sine function, with major x ticks every π units and major y ticks every 1 unit.  Note the default is to label only the left and bottom side of the frame.

Plot[Sin[x], {x, 0, 4  Pi}, Frame -> True, 
        FrameTicks -> 
          FrameTickTable[{Pi, Pi/4}, {1, 0.2}]];

Here is the same plot, without the last major tick label on the x-axis.  (Getting rid of tick labels near  edges can be useful, for example, if the plot will be combined with another plot in an array.)

Plot[Sin[x], {x, 0, 4  Pi}, Frame -> True, 
        FrameTicks -> 
          FrameTickTable[{Pi, Pi/4, NoLastLabel -> True}, {1, 
              0.2}]];

Here is a plot with tick labels on the top and right sides.

gr  =  
        Plot[Sin[x], {x, 0, 4  Pi}, Frame -> True, 
          FrameTicks -> 
            FrameTickTable[{Pi, Pi/4}, {1, 0.2}, 
              TickLabel -> {False, True}]];

Here is a plot with unlabeled y ticks and x ticks labeled (with reversed sign) on both top and bottom edges, where both x and y major ticks are extra large.

Plot[Sin[x], {x, 0, 4  Pi}, Frame -> True, 
        FrameTicks -> 
          FrameTickTable[{Pi, Pi/2, ReverseAxis -> True, 
              TickLabel -> True}, {1, 0.5, TickLabel -> False}, 
            MajorSize -> 0.05], 
        PlotRange -> {{0, 4 Pi}, {-1.5, 1.5}}];

Here is a plot with frame and ticks thicker than the default.  Frame will be 3 pts thick;  major ticks will be 2 pts thick; minor ticks will be 1 pt thick.

gr  =  
        Plot[Sin[x], {x, 0, 4  Pi}, Frame -> True, 
          FrameStyle -> AbsoluteThickness[2], 
          FrameTicks -> 
            FrameTickTable[{Pi, Pi/4}, {1, 0.2}, 
              MajorStyle -> AbsoluteThickness[2], 
              MinorStyle -> AbsoluteThickness[1]]];

The plot style can be changed via the PlotStyle or Prolog option as usual, without affecting the frame or ticks.  Here is the same plot, with the curve dashed and colored red.

Show[gr, 
        Prolog -> {RGBColor[1, 0, 0], Dashing[{0.06}]}];

Plots for Publication

Journals urge that line widths, tick lengths, and tick labels of any graphics submitted for publication be bold enough for good legibility when reduced.  Unfortunately, the default frame ticks and line style in Mathematica (v.4.2) are less bold than most journals prefer.  The default tick lengths can be too short to see easily, and the default line thickness are thinner than the minimum recommended (0.5 pt).  Also, many authors prefer a font such as Helvetica for labels, rather than Mathematica's default Courier-like font.  The notes below show how to deal with several problems often encountered when trying to create plots suitable for publication.
The notes start by showing what the standard Mathematica defaults are and how to reset those defaults, using the TickControl package, for bolder ticks, lines, and labels.   Then they demonstrate how to use TickControl to create plots of data where one or more axes must be reversed—a situation often faced by astronomers.
The next examples show how to create good-looking plot arrays, by using TickControl together with another non-standard package:  StackedGraphicsArray by Markus Lischka (available from the MathSource archive at the Wolfram website http://www.wolfram.com).  Lischka's package creates arrays of plots with aligned axes.  The TickControl package gives control over tick size, placement, labels, and axis direction of individual plots within an array, and also provides a function which expands labeling options for the array.
The notes finish with an example showing how to export a completed graphic to an encapsulated postscript file.

Note:  To make the StackedGraphicsArray package accessible, yet keep it separate from the standard packages, put it inside the same folder created for TickControl (AddOns —> ExtraPackages —> Graphics).

System Defaults

Here is a framed plot produced by the system defaults.

pl1  =  
        Plot[Sin[x], {x, 0, 2  Pi}, Frame -> True];

This shows the default thickness of the frame (0.25 pt in Mathematica 4).

AbsoluteOptions[pl1, FrameStyle]

This shows the default thicknesses  (0.25 and 0.125 pts, respectively) and the default lengths (0.00625 and 0.00375) of major and minor ticks.  (Note: if list does not display, change number of lines in Short.)

AbsoluteOptions[pl1, FrameTicks] // Short[#, 5] &

This plot shows the default size of points.

data = 
        Table[{Random[], Random[]}, {10}];
pl2  =  
        ListPlot[data, Frame -> True, Axes -> False];

Resetting Defaults

Here's how to reset the defaults for longer and thicker ticks, using the TickControl package.  You can reset the frame style to match, and also change the default line style, point style, and font, using built-in functions.
The minimum line thickness suggested by journals is 0.5 pt, so a good choice for a new default is AbsoluteThickness[0.5] or AbsoluteThickness[1].  You can also use Thickness[0.005], but note that the line thickness will then scale up or down as the plot scales up or down.
Points, like lines, can be scalable in size or absolute.  For points which will remain legible no matter what the reduction, try AbsolutePointSize[2] to AbsolutePointSize[4].  For scalable points, try PointSize[0.01] or PointSize[0.02].
One way to change the default font is to use $TextStyle.  The original setting is $TextStyle = {}. Setting one or more FontFamily, FontSize, etc., options in $TextStyle will override that option in the system default.

Note:  Once a plot is exported to an encapsulated postscript file and included in a TEX file, the font size of the text will scale up or down as the image is scaled up or down.  However, points and lines with AbsolutePointSize, AbsoluteThickness, or AbsoluteDashing will not; they will always remain 5 pt thick, or whatever, no matter what the size of the plot.  (This can cause problems if plots with AbsoluteDashing are scaled too small:  the dashing spacing can become too large relative to the line length.)  If you want lines and points that scale up and down with the text, so that the plot always retains its original proportions, use PointSize, Thickness, and Dashing.  On the other hand, if you want to ensure that lines and points will always be legible no matter what the reduction, or if you want to ensure that plots of different reductions look similar, use absolute sizes.

This loads the package (if not already loaded).

<< Graphics`TickControl`

Here's a new line thickness.

newthick = AbsoluteThickness[0.5];

This resets the tick styles to make them thicker.  Note that the major and minor tick lengths are already reset longer than the standard Mathematica default.

SetOptions[FrameTickTable,  MajorStyle -> newthick, 
      MinorStyle -> newthick]

These reset Plot's and ListPlot's default frame and plot styles, and sets Frame to True.

SetOptions[Plot, Frame ->  True,  FrameStyle -> newthick, 
        PlotStyle -> newthick];

SetOptions[ListPlot, Frame -> True, FrameStyle -> newthick, 
        PlotStyle -> {newthick, AbsolutePointSize[4]}];

This changes the default font family (but leaves the size the same as before).

$TextStyle = {FontFamily -> Helvetica};

Here's a plot showing the some of the new defaults.

pl2 = 
        Plot[Sin[x], {x, 0, 4  Pi}, PlotRange -> {-2, 2}, 
          FrameTicks -> FrameTickTable[{Pi, Pi/4}, {1, 0.25}]];

This makes the default font size smaller.

$TextStyle = {FontFamily -> Helvetica, 
          FontSize -> 10};

Note that changing $TextStyle affects previously generated graphics as well as new ones.

Show[pl2];

Plots with Reversed Axes

Astronomers often have to construct plots with reversed axes, such as when they are plotting some quantity vs. magnitude (which gets brighter the smaller the number is).  TickControl's ReverseAxis option makes this easier.  The example below shows one way to do it.

Here is a list of names, distances, and absolute magnitudes for five galaxies (Lang 1980, Astrophysical Formulae).

gals = {{"NGC45", 2.4, -16.45}, {"NGC55", 
            2.4, -20.38}, {"NGC157", 
            15.1, -20.24}, {"NGC221", 
            0.69, -15.7}, {"NGC224", 0.69, -21.81}};

Define a function that will pull out the coordinates to be plotted, and multiply the coordinate to be reversed by -1.

ff[{name_, dist_, mag_}] := {dist, -mag}

Plot the data, using FrameTickTable to specify the tick spacing and setting ReverseAxis to True for the y-axis.

gr = 
        ListPlot[Map[ff, gals], 
          FrameTicks -> 
            FrameTickTable[{5, 1}, {2, 1, 
                ReverseAxis -> True}]];

Here's the plot with frame labels, and other settings adjusted to look better.  When adjusting the plot range, remember that the y-coordinates of the plot data have the opposite sign as what appears on the y-axis.

Show[gr, PlotRange -> {{0, 20}, {14, 26}}, Axes -> None, 
        FrameLabel -> {"Distance (Mpc)", "Absolute Magnitude"}, 
        ImageSize -> 200];

Arrays

It's often useful to combine several plots into an array drawn such that axes of the plot areas coincide and interior tick labels are removed.  The third party package Graphics`StackedGraphicsArray` has functions that accomplish this easily for most plots.

This loads the package.

<< Graphics`StackedGraphicsArray`

Here's info about StackedGraphicsArray.

?StackedGraphicsArray

Here are some frame labels.

labs = {"x-coordinate", "y-coordinate"};

This sets some options useful for making sample plots.

SetOptions[Plot, FrameLabel -> labs, 
        FrameTicks -> FrameTickTable[{Pi, Pi/4}, {1, 0.25}], 
        PlotRange -> {{-3 Pi, 3  Pi}, {-2, 2}}, 
        Axes -> None, DisplayFunction -> Identity];

Here are graphics of two sample plots.

{plot1, plot2} = {Plot[Sin[x], {x, -2 Pi, 2  Pi}], 
          Plot[Cos[2  x], {x, -2 Pi, 2  Pi}]};

This resets the default size for displayed graphics.

SetOptions[Graphics, ImageSize -> 290];

Here's an array made with the plots.   Note that the tick labels overlap where the plots meet.

Show[StackedGraphicsArray[{plot1, plot2}]];

Strategies for dealing with overlapping tick labels

One way to avoid overlapping tick labels in an array is to separate individual plots, using the GraphicsSpacing option.   Note however that StackedGraphicsArray automatically removes interior tick labels only when GraphicsSpacing is 0.  If you don't want interior labels when plots are separated, you have to manually remove them, using StackedGraphicArray's StackedLabel option.

Here's info about the StackedLabel option.

?StackedLabel

This inserts a space between the plots.  Note that the interior tick and axes labels are retained with the default setting of StackedLabel.

Show[
        StackedGraphicsArray[{plot1, plot2}, 
          GraphicsSpacing -> 0.3]];

This removes the y-axis labels on the second plot.

Show[
        StackedGraphicsArray[{plot1, plot2}, GraphicsSpacing -> 0.3, 
          StackedLabel -> {{Automatic, Automatic, None, 
                None}, {Automatic, None, None, None}}]];

Another way to deal with overlapping tick labels is to regenerate individual plots without the first and/or last tick label, using TickControl's NoFirstLabel and/or NoLastLabel options.

This resets the default frame ticks so there will be no first or last tick labels on any axis.

SetOptions[MajorTickTable, NoFirstLabel -> True, 
        NoLastLabel -> True];

This regenerates the plots.

{plot1, plot2} = {Plot[Sin[x], {x, -2 Pi, 2  Pi}], 
          Plot[Cos[2  x], {x, -2 Pi, 2  Pi}]};

Now there are no overlapping tick labels in the array.  Note the array can be made larger than the default size by using the ImageSize option in Show.

Show[StackedGraphicsArray[{plot1, plot2}], 
        ImageSize -> 400];

Labels

Sometimes it's useful to run a common label across an entire edge of an array, instead of having multiple individual ones.  The function AddFrameLabel included in the TickControl package will do this.  (Note:  This function will work for any graphic, not just arrays.)

Adding frame labels around a graphic.

Here are four sample plots without individual frame labels.

{pl1, pl2, pl3, pl4} = 
Table[
          Plot[Sin[n x], {x, -2 Pi, 2  Pi}, 
            FrameLabel -> None], {n, 1, 4}];

Here they are combined in an array.

grarray = 
        Show[StackedGraphicsArray[{{pl1, pl2}, {pl3, pl4}}], 
          DisplayFunction -> Identity];

Here is the array with some labels.  Notice the fourth label is oriented the same as the second label (reads from bottom to top).  As usual, labels running vertically will print out correctly, even though they don't display correctly.

AddFrameLabel[
        grarray, {"Label 1", "Label 2", "Label 3", "Label \
4"}];

AddFrameLabel accepts all the standard options for Graphics and StyleForm, as well as two new options (XLabelOffset and YLabelOffset) that allow fine-tuning of the label positions.

Options for AddFrameLabel

This labels just the first and third side, and centers them a little better.

AddFrameLabel[grarray, {"Label 1", "", "Label 3"}, 
        XLabelOffset -> {-0.5, 1}];

This adds coordinate labels in larger font running along the x and y axes, centered and pushed away from the plot to give the tick labels more room.

\(\(AddFrameLabel[
        grarray, {\*""x-coordinate (km (Mpc^(-1))(s^(-1)))"", \*""y-coordinate (Mpc (Ω^(-2)))""}, 
        FontSize -> 12, XLabelOffset -> {\(-0.2\), 1.5}, 
        YLabelOffset -> {2, \(-0.1\)}];\)\)

Because AddFrameLabel first puts the graphic into a Rectangle, it works properly even with a stacked graphics array that has spacing added between the individual elements via the GraphicsSpacing option.  (This is not always true if the labels are simply added as Text primitives to the original graphic.)

Here are plots with individual frame labels.

{pl1, pl2, pl3, pl4} = 
Table[
          Plot[Sin[n x], {x, -2 Pi, 2  Pi}], {n, 1, 4}];

Here are settings for StackedLabel that will get rid of the interior labels.

yL = {None, Automatic, None, None};
xL = {Automatic, None, None, None};
xyL  =  {Automatic, Automatic, None, None};
noL = {None, None, None, None};
fourstackedlabels  =  {{yL, noL}, {xyL, xL}};

Here's an array that retains the individual frame labels (outside edges only) and reduces the font size of the frame labels (but not the tick labels).  Note that you must specify the font family as well as the size in the TextStyle option, or the font of the frame labels will revert to the system default.

grarray2 = 
        Show[StackedGraphicsArray[{{pl1, pl2}, {pl3, pl4}}, 
            GraphicsSpacing -> {0.1, 0.15},  
            StackedLabel -> fourstackedlabels, 
            TextStyle -> {FontSize -> 8,  
                FontFamily -> Helvetica}]];

We can use AddFrameLabel to attach a plot title.  Also, text labels such as "(a)", "(b)", etc., can be added to the array at the same time, via the Epilog option.  Note that positions are specified in scaled coordinates, relative to the rectangle enclosing the graphic.  Also, the fonts of these Text primitives will conform to the current $TextStyle, unless the TextStyle option is reset.

Here is a new TextStyle option suitable for big individual labels.

bigfont = 
      TextStyle -> $TextStyle /. (10 -> 16)

Here is the array with a centered title and a couple sample labels inside the plots.  Note that in this example each kind of label is a different size.  Tick labels are the default size (10 pt); frame labels are smaller (8 pt); the plot title is larger (12 pt); and text labels are largest (16 pt).

\(\(finalplot = 
AddFrameLabel[
          grarray2, {"", "", "Four Important Sets of Data"}, 
XLabelOffset -> {\(-0.2\), 1}, FontSize -> 12, 
          Epilog -> {Text["(a)", {\(-0.1\), 0.5}, bigfont], 
              Text["(b)", {0.8, 0.5}, bigfont]}];\)\)

Exporting a graphic to an EPS file

Here are sample commands for saving the second plot on the Desktop in form suitable for including in a TEX document (as an encapsulated postscript file called "figure.eps").  ImageSize is given in printer's points; note that there are 72 pts per inch.  Note that if ImageSize is omitted, the figure will be saved in the default size.  To ensure good placement of text labels, manually resize so that  text is in desired proportion to plot, then save at that size (select Show Ruler from the Format menu  to estimate size in inches, or click on the bounding box handle to see width in printers points).

SetDirectory["/Users/e_praton/Desktop"];
Export["figure.eps", finalplot, "EPS", 
      ImageSize -> 4*72]