Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

From the Documentation,

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}}}}]

plot

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?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

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:

enter image description here

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:

enter image description here

share|improve this answer
    
+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}}}}]

ticks 1

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

ticks2

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.

ticks 3

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.

share|improve this answer
    
+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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.