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.

When I make a plot like

Plot[Exp[x], {x, 1 - 10^-9, 1}]

The resulting plot looks like

exp plot near 1.

Notice all the ticks on the x-axis are all labeled 1. Is there any way to increase the precision of the tick labels? So that the ticks are labeled something like 0.999999999, or 1-10^{-10} etc.

share|improve this question
add comment

3 Answers 3

up vote 11 down vote accepted

You have to understand, that all the automatic methods, be it adaptive sampling, labeling, etc, work in most cases, but it is always possible to break them. This can happen when you are plotting very small values or very large one or when your function has very small features. For those cases, you can often manually adjust the settings.

For the ticks you have several options. First, you can set them manually to any label you like

Plot[Exp[x], {x, 1 - 10^-9, 1}, 
 Ticks -> {{{999999999/1000000000, "close to 1"}, 
            {1499999999/1500000000, "very close to 1"}, 
            {2999999999/3000000000, "even closer to 1"}, 
            {1, "finally 1"}}, 
   Automatic}]

enter image description here

Here, the strings I used can be any representation of the values you like. Furthermore, you can use a function which takes xmin and xmax of your plotting interval and gives back a list of tick information

tickfunc[xmin_, xmax_] := 
 Table[{x, NumberForm[x, 10]}, {x, xmin, xmax, (xmax - xmin)/4}]

Plot[Exp[x], {x, 1 - 10^-9, 1}, Ticks -> {tickfunc, Automatic}]

enter image description here

There are some more options and you can look at the documentation for Ticks to find out more. Finally, you could post-process an existing plot, by extracting the created Ticks and adjust them. With AbsoluteOptions you can extract the given Ticks of a Graphics and then it is simple replacement

gr = Plot[Exp[x], {x, 1 - 10^-9, 1}];
gr /. Graphics[blub__] :> 
  Graphics[blub, 
   First[(AbsoluteOptions[gr, 
       Ticks] /. {a_Real, b_, rest___} :> {a, 
        Rotate[Text[NumberForm[b, 10]], Pi/8], rest})]]

Note that you have to be a bit creative here, since otherwise the long numbers won't fit in the given place. Therefore, I rotated the labels a bit.

enter image description here

share|improve this answer
add comment

You can always set your own ticks. Here you need to set precision and in the case of long numbers also, perhaps, - rotation. You can also control how many ticks you have and along which axis.

in = 1`11 - 10^-9; fi = 1.`11;
tks = Table[{n, Rotate[n, Pi/2]}, {n, in, fi, (fi - in)/10}];
Plot[Exp[x], {x, 1 - 10^-9, 1}, Ticks -> {tks, Automatic}]

enter image description here

To make labels shorter you can use AxesLabel trick:

in = 1`11 - 10^-9; fi = 1.`11;
tks = Table[{n, Rotate[n - 1, Pi/4]}, {n, in, fi, (fi - in)/5}];
Plot[Exp[x], {x, 1 - 10^-9, 1}, Ticks -> {tks, Automatic}, 
 AxesLabel -> {Style[1 + x, Bold, Blue, 13], Style[y, Bold, Blue, 13]}]

enter image description here

share|improve this answer
add comment

How about this:

plotA = Plot[Exp[x], {x, 1 - 10^-9, 1}];

newTicks=AbsoluteOptions[plotA, Ticks][[1, 2, 1]] /. 
  {x1_, x2_, x3_, x4_} -> {x1, x2, {0.00625`, 0.`}, x4} /. 
  {x1_, x2_, x3_, x4_} /;x1 == x2 :> {x1, ToString@AccountingForm[x1, 10], {0.01, 0}, x4}

Plot[Exp[x], {x, 1 - 10^-9, 1},Ticks -> {newTicks, Automatic}]

enter image description here

Edit

with NumberForm it is possible to present numbers in 1-n*10^{-10} form

newTicks=AbsoluteOptions[plotA, Ticks][[1, 2, 1]] /. 
  {x1_, x2_, x3_, x4_} -> {x1, x2, {0.00625`, 0.`}, x4} /. 
  {x1_, x2_, x3_, x4_} /;x1 == x2 :> {x1, 
    ToString@NumberForm[1 - x1,NumberFormat -> (
       SequenceForm["1-", #1, "\[Times]", #2,"^",{#3}] &)], {0.01, 0}, x4}

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.