# How to set tick label precision [duplicate]

When I make a plot like

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


The resulting plot looks like .

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.

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}] 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}] 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. • doesnt seem to work in matehamtica 10 Oct 2 '14 at 23:02

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 = 111 - 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}] To make labels shorter you can use AxesLabel trick:

in = 111 - 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]}] 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}] 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} 