# Getting consistent Ticks lengths and TickLabels positioning

Tick mark lengths are given as a fraction of the distance across the whole plot.

I wish to have identical tick mark lengths for both horizontal and vertical ticks and I wish them to look outside of the plot area. For this I multiply the horizontal tick lengths by GoldenRatio that is the default for Plot-like functions:

Plot[Cos[x], {x, 0, 10}, Frame -> True, Axes -> False,
FrameTicks -> {{{0, 0, {0, .2 GoldenRatio}}, {Pi,
180, {0, .2 GoldenRatio}}, {2 Pi,
360, {0, .2 GoldenRatio}}, {3 Pi,
540, {0, .2 GoldenRatio}}}, {{0, 0, {0, .2}}}}]


As you see, the horizontal TickLabels are positioned correctly but at the bottom and at the top the real length of ticks are ignored and TickLabels are positioned as it is by default (if I remove the GoldenRatio multiplication). Is it possible to position TickLabels correctly?

-

I really don't know how the problem come from, but I finally fix it with a small trick and wait for others to solve it completely.

The ticks label only react to the longest tick when AspectRatio applied to the plot. So here I add one tick with the same mode but a longer length {2.3 \[Pi], 80, {0, 0.6}}}:

Plot[Cos[x], {x, 0, 10}, Frame -> True, Axes -> False,
FrameTicks -> {{{0, 0, {0, .1 }}, {Pi, 180, {0, .1 }}, {2 Pi,
360, {0, .1 }}, {3 Pi, 540, {0, .1 }}, {2.3 \[Pi],
80, {0, 0.2}}}, {{0, 0, {0, .1}}}}, AspectRatio -> 1/2]


And the result:

Then just make the extra tick fade away, of course you can change the length of extra one to make your plot look pretty:

Plot[Cos[x], {x, 0, 10}, Frame -> True, Axes -> False,
FrameTicks -> {{{0, 0, {0, .2 GoldenRatio}}, {Pi,
180, {0, .2 GoldenRatio}}, {2 Pi,
360, {0, .2 GoldenRatio}}, {3 Pi,
540, {0, .2 GoldenRatio}}, {2.3 \[Pi], , {0, 0.52},
Transparent}}, {{0, 0, {0, .2}}}}]


And the result:

-
+1. Good workaround! Although I hoped there is a straighforward way. – Alexey Popkov Aug 20 '12 at 18:06

Diagnosis

It appears that MMA misplaces tick labels when the ticks are long and the AspectRatio is different from 1.

If you set the AspectRatio to 1 and use the same values for the horizontal and vertical tick lengths, the appearance looks fine.

ts = .1;
Plot[Cos[x], {x, 0, 10}, Frame -> True, Axes -> False,
AspectRatio -> 1,
FrameTicks -> {{{0, 0, {0, ts}}, {Pi, 180, {0, ts}}, {2 Pi,
360, {0, ts}}, {3 Pi, 540, {0, ts}}}, {{0, 0, {0, ts}}}}]


Now let's set the AspectRatio -> 1/GoldenRatio and see what happens:

The vertical and horizontal ticks appear to be of the same length. However, the horizontal labels are positioned over the end of the respective ticks.

Possible Workaround

Now, if you use "aesthetically appealing" tick lengths, ts = .025, the problem fails to show up, as far as I can tell.

I'm not sure what you might do to get the tick labels properly placed if you want really long ticks. Playing with ImagePadding does not help.

Btw, I interpret the documentation's statement, "Tick mark lengths are given as a fraction of the distance across the whole plot." as meaning that the plot width is used for determining the size of the tick lengths (both horizontal and vertical) when they are manually set. So the AspectRatio does not appear to influence tick lengths.

-
+1. You are seemingly right with the interpretation of the docs statement: setting AspectRatio -> 1/60 makes this obvious. But ts = .025 is not a solution, of course. – Alexey Popkov Aug 20 '12 at 18:01