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 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 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] & /@ 
    {Charting`ScaledTicks[{Identity, Identity}], 
     Charting`ScaledFrameTicks[{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.

Continue reading