# Increasing Axes Tick Length With Mathematica

One of my long-standing criticisms of Mathematica’s graphics is the ultra small default tick marks used most graphics. I assume the goal is to not have people focus on the tick marks but on the plot content, but the default tick marks are so small that any analysis of the graphic is difficult. You can find numerous posts online asking how to increase the tick length, but few simple solutions (that don’t rely on external packages). As I have described in earlier posts you can define you own tick marks and pass those to any common graphics command, which is fine for custom final figures, but for general applications the requirement that you know the best major and minor tick spacings makes it tedious.

While searching for a fix for a bug in the LogLogPlot command (which doesn’t even let you change tick thickness) I came across some examples on stackexchange.com that used some private Charting functions to compute the major and minor tick lists. I haven’t found any detailed help on these functions, but the stackexchange.com descriptions were enough to get something working.

#### Linear Axes

Here’s my function for asking Mathematica for nicely spaced major and minor ticks but increasing the length of the tick marks.

(* arguments: min and max axis value, scale factor for tick length *)
GetScaledLinearTicks[min_, max_, scale_] := Module[{ticks},
ticks = #[min, max] & /@
{ChartingScaledTicks[{Identity, Identity}],
ChartingScaledFrameTicks[{Identity, Identity}]};
(*scale the tick length*)
Table[{#[[1]], #[[2]], scale*#[[3]]} & /@ ticks[[i]], {i, 2}]]

Here’s an example usage,

lticks = {GetScaledLinearTicks[-1.1, 1.1, 2.5],
GetScaledLinearTicks[-3.2, 3.2, 2.5]};
(**)
pd = Plot[Cos[x], {x, -Pi, Pi}, Frame -> True, ImageSize -> 300,
PlotLabel -> "Default Tick Length"];
(**)
pl = Plot[Cos[x], {x, -Pi, Pi}, Frame -> True,
FrameTicks -> lticks, PlotLabel -> "Tick Length Scaled by 2.5"];
(**)
GraphicsRow[{pd, pl}] // Print

and here is the default and scaled tick length outputs,

Default and scaled ticks using the function listed above. The axes limits are not exactly the same, but are close enough to produce the same major and minor tick spacing.

You have to set the minimum and maximum axes limits to use these functions. I often specify them myself using PlotRange, so that’s usually not a problem. If you need, you can get the default plot range from an initial call to the plot. So far these functions have returned reasonable major and minor ticks lists that I can pass with the FrameTicks option in my plots.

#### Logarithmic Axes

For logarithmic axes, we have to work with the fact that Mathematica uses natural logarithms in the computations and convert our limits to logarithms and back to the original values.

GetScaledLogTicks[min_, max_, scale_] :=
Module[{ticks},
ticks = #[Log[min],Log[max]] & /@ {ChartingScaledTicks[{Log, Exp}],
ChartingScaledFrameTicks[{Log, Exp}]};
(*scale the tick length*)
Table[{Exp[#[[1]]], #[[2]], scale*#[[3]]} & /@ ticks[[i]], {i, 2}]]

Table[{Exp[#[[1]]], #[[2]], scale*#[[3]]} & /@ ticks[[i]], {i, 2}]]

xmin = 0.001;
xmax = 0.5;
ymin = 2 10^(-3);
ymax = 5;
(**)
lticks = {GetScaledLogTicks[ymin, ymax, 2.5],
GetScaledLogTicks[xmin, xmax, 2.5]};
(**)
tau = 25.0;
pd = LogLogPlot[Sin[2 Pi f tau ]/(2 Pi f tau), {f, 0, 0.5},
PlotRange -> {{xmin, xmax}, {ymin, ymax}}, Frame -> True,
ImageSize -> 300, PlotLabel -> "Default Tick Length"];
(**)
pl =
LogLogPlot[Sin[2 Pi f tau]/(2 Pi f tau), {f, 0, 0.5},
PlotRange -> {{xmin, xmax}, {ymin, ymax}}, Frame -> True,
FrameTicks -> lticks, PlotLabel -> "Tick Length Scaled by 2.5"];
(**)
GraphicsRow[{pd, pl}] // Print

and here’s the output,

Default and scaled ticks using the function listed above. The axes limits are specified explicitly.

The tick selection here is not great, but since we have a list of major and minor ticks, we could drop the values that correspond to half-decade labels.

#### Summary

I stumbled into the stackexchange.com solutions but wrote my own versions that may be less efficient and less concise that other versions, but mine are clear enough for me to maintain and debug if things change in the future.

#### References

Here are links to the stackexchange.com discussions that provided the how-to for these work-arounds.

https://mathematica.stackexchange.com/questions/57425/thickness-of-logarithmic-tick-marks

https://mathematica.stackexchange.com/questions/51367/export-high-resolution-figure-causes-missing-ticks/107473#107473