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.

How can I align tick labels so the tick label text ends centered under the data point? Of Course it works fine with a rotation of 90 Degrees, but not with 45 or similar angles.

I see an example of how to do this charts but not with Plot or ListPlot http://mathematica.stackexchange.com/a/2656/388

d = Table[n, {n, 10}];
xticks = Table[{n, 
Rotate["The y value is " <> ToString[n], 45 Degree]}, {n, d}];
ListPlot[d, Frame -> True, 
 FrameTicks -> {{Automatic, None}, {xticks, None}}]

Labeled list plot

share|improve this question
    
Related: mathematica.stackexchange.com/q/4791/8 –  Verbeia Aug 16 '12 at 22:53
    
It actually is centered... Try for example with xticks = Table[{n, Rotate["The y value is " <> ToString[n], 45 Degree], {0, 0.2}}, {n, d}]; and you'll see that it intersects the text at its midpoint –  rm -rf Aug 16 '12 at 23:31
2  
@R.M "text ends centered" –  Mr.Wizard Aug 17 '12 at 11:46
add comment

1 Answer

up vote 4 down vote accepted

Similar to Szabolc's and my answers here, I would suggest writing your own custom tick function, so that the labels are set into a Pane which can be both Rotated and have ImageMargins.

myTickList[min_, max_, seg_, shift_?NumericQ, phi_?NumericQ, len_: 0.01] := 
 Table[{i, Rotate[Pane[Style["y =" <> ToString[i], LineSpacing -> {0, 12}], 
     FrameMargins -> {{shift, 0}, {0, 0}}], phi], {len, 0}}, 
    {i, If[Head[seg] === List, Union[{min, max}, seg], 
    Range[min, max, seg]]}]

Examples:

fakedata = Accumulate@RandomVariate[NormalDistribution[0, 0.5], 40];

ListLinePlot[fakedata, Frame -> True, GridLines -> {None, Automatic}, 
 FrameTicks -> {{Automatic,  Automatic}, {myTickList[0, 40, 4, 25, Pi/4], None}}]

enter image description here

ListLinePlot[fakedata, Frame -> True, GridLines -> {None, Automatic}, 
 FrameTicks -> {{Automatic, Automatic}, {myTickList[0, 40, 4, 5, Pi/3], None}}]

enter image description here

share|improve this answer
add comment

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.