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.

Is there a convenient way to format tick labels? In this example I would like to use the default Mathematica tick intervals, but simply convert the X axis labels to strings with "s" added.

As you can see below, by default Mathematica shows six X axis labels, with three subticks, although for different plot ranges both can vary:

plotA = Plot[Sin[x], {x, 6, 16}, Frame -> True]

enter image description here

A basic function can be defined to add the "s" formatting, but it doesn't vary as the Mathematica range would. Adding subticks would be further work, and the upper X frame would have to be defined too, to match the intervals.

frametickfunction[xmin_, xmax_] :=
 {#, ToString[#] <> "s"} & /@ FindDivisions[{xmin, xmax}, 6]

plotB = Plot[Sin[x], {x, 6, 16}, Frame -> True,
 FrameTicks -> {{True, True}, {frametickfunction, True}}]

enter image description here

It would be convenient if I could obtain the X axis specification produced in plotA, modify it, and use it in plotB. Is this possible, or are there other methods?

share|improve this question
2  
AbsoluteOptions[] is supposed to be the solution for this, but it seems it doesn't do what it's supposed to do in these recent versions of Mathematica... –  J. M. Jun 15 '12 at 10:00
    
This question might be helpful –  Heike Jun 15 '12 at 11:06
    
I recommend writing your own tick function and/or using the CustomTicks function of LevelScheme: scidraw.nd.edu/levelscheme –  tkott Jun 15 '12 at 15:20
add comment

1 Answer 1

up vote 8 down vote accepted

as J. M. said , you have to use AbsoluteOptions

plotA = Plot[Sin[x], {x, 6, 16}, Frame -> True];

newTicks = AbsoluteOptions[plotA, FrameTicks][[1, 2,  1]] /. 
{x1_, x2_, x3_, x4_} /; x1 == x2 :> {x1, ToString[Floor@x2] <> " s", x3, x4}

 Plot[Sin[x], {x, 6, 16}, Frame -> True, 
 FrameTicks -> {{Automatic,Automatic}, {newTicks, Automatic}}]

enter image description here

Edit

for some reason the tick size is different

newTicks = AbsoluteOptions[plotA, FrameTicks][[1, 2, 1]] /. 
 {x1_, x2_, x3_, x4_} -> {x1, x2, {0.00625`, 0.`}, x4} /. 
 {x1_, x2_, x3_, x4_} /;x1 == x2 :> {x1, ToString[Floor@x2] <> " s", {0.01, 0}, x4}; 

Plot[Sin[x], {x, 6, 16}, Frame -> True, 
FrameTicks -> {{Automatic, Automatic}, {newTicks, Automatic}}]

enter image description here

share|improve this answer
    
"for some reason the tick size is different" - that's what I was alluding to in my comment; AbsoluteOptions[] doesn't precisely return the sort of ticks used. –  J. M. Jun 15 '12 at 16:31
2  
Does anyone know if it is possible, in some way, perhaps undocumented, to specify a tick length in printers points rather than scaled length -- without doing calculations for the conversion. It would be useful if that were possible. –  Mike Honeychurch Jun 15 '12 at 23:08
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.