# pgfplots error: dimension too large

I am trying to generate a LaTeX pgfplot:

\begin{tikzpicture}
\begin{axis}[
xmin=.2,xmax=.5,
ymin=-.00000000000000001,ymax=.00000000000000001,
xlabel=Distance a (nm),
ylabel=Force F (mJ/nm)
]

\end{axis}
\end{tikzpicture}


This generates the error "dimension too large." What could be wrong?

• Welcome to TeX.SX! The number range and the precision supported by TikZ are limited. Try to rewrite the formulas to avoid that intermediate results get out of range or divisors get too close to zero. – Heiko Oberdiek Apr 19 '17 at 5:47
• The error goes away when I used one less zero for ymax. That is,1e-16. – Troy Apr 19 '17 at 5:48
• Welcome to TeX.SE. For future reference, while code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. – Peter Grill Apr 19 '17 at 5:57
• you are way past tex's numerical accuracy there so specifying a range from essentially 0 to 0 . Even with a few less zeros so it doesn't error, you will just be getting essentially rounding error for the y values – David Carlisle Apr 19 '17 at 8:23
• Did my answer help you to solve your problem or do you need further assistance? If so, please let us know what you are still missing. Thank you. – Stefan Pinnow Apr 22 '17 at 9:28

The error is caused due to a "scaling" problem which can be avoided when you change the domain to the values near the range that is "visible" in the total plot. So simply narrowing down domain to 0.3:0.5 avoids the error.

% used PGFPlots v1.14
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{
compat=1.3,
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=.2,xmax=.5,
ymin=-1e-17,
ymax=+1e-17,
xlabel=Distance a (nm),
ylabel=Force F (mJ/nm),
% ---------------------------------------------------------------------
% changed domain' to "visible" part of the plots to avoid
% the "dimension to large" error
domain=0.3:0.5,
% ---------------------------------------------------------------------
% added smooth' so the plots look better
smooth,
]