# pgfplots to plot a function from [4,4.001]

When I try to plot a function on a small range, the output is an empty graph from 0 to 1 on the x and y axis. What can I do to fix this? My tex looks like this:

\begin{tikzpicture}
\begin{axis}[
xmin=4.0,
xmax=4.001,
samples=60,
xlabel=$time$,
ylabel={$acceleration$}
]

\end{axis}
\end{tikzpicture}


You can rescale the calculation:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
xmin=0,
xmax=1,
samples=60,
xlabel=$time$,
xticklabel=\pgfmathparse{4+\tick/1000}\pgfmathresult,
ylabel={$acceleration$}
]

\end{axis}
\end{tikzpicture}

\end{document}

• How does this line work? xticklabel=\pgfmathparse{4+\tick/1000}\pgfmathresult
– Greg
May 16 '13 at 0:29
• @user2116192 as far as I understand it (which isn't far, I've never used tikz apart from the occasional answer here) \pgfmathparse is the general utility function in pgf to evaluate an expression, leaving its result in \pgfmathresult in this context \tick is the value going from 0 to 1 which would be the default label, but by setting the xticklable key it comes out as 4.00.. instead. May 16 '13 at 0:34
• It may be worth mentioning the library fixedpointarithmetic, which uses the fp package for calculations (9 digits before and 9 after the decimal point). May 16 '13 at 9:30

The problem here is that the function isn't evaluated within the axis range. The standard domain is -5:5 (this is not changed by setting xmin and xmax), so with 60 samples, the function is evaluated at 3.98 and 4.15. If you set the domain=4:4.001 (so equal to the visible range set using xmin and xmax), the data is plotted correctly without any manual coordinate transformations:

\documentclass[border=5mm]{standalone}

\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
samples=60,
xmin=4.0, xmax=4.001,
domain=4:4.001,
xlabel=Time $t$,
ylabel=Acceleration $a$,
ticklabel style={ % Make sure all relevant digits are printed
/pgf/number format/.cd,
fixed,
fixed zerofill,
precision=4
}
]


• By the way, instead of $time$/$acceleration$ in the labels we should write \textit{...} if we want italic text or simply ... if we want it upright. Not the math mode. May 21 '13 at 17:34
• Thanks for the response. It shows that as $\Delta t$ shrinks to zero, the acceleration tends toward some value, which allows one to plot complicated motion with a few simple equations and a computer. Thanks again!