Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Bug introduced in 7 or earlier and persists through 10.3.1 or later


I'm trying to have identical tick mark lengths for both horizontal and vertical ticks and I wish them to look outside of the plot area. But at the final plot tick mark labels overlap with tick marks:

Plot[Cos[x], {x, 0, 10}, Frame -> True, Axes -> False, 
 FrameTicks -> {{{0, 0, {0, .015}}, {Pi, 180, {0, .015}}, {2 Pi, 360, {0, .015}}, {3 Pi, 
     540, {0, .015}}}, {{0, 0, {0, .015}}}}, ImageSize -> {1000, 200}, AspectRatio -> 1/6]

plot

Is it possible to position tick mark labels correctly?

share|improve this question

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

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

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.